Open dschiller opened 4 years ago
Implemented like this:
ftp-config.js
( C:\Users\<User>\.vscode\extensions\lukasz-wronski.ftp-sync-0.3.9\modules
)
defaultConfig: {
remotePath: "./",
host: "host",
username: "username",
password: "password",
port: 21,
secure: false,
protocol: "ftp",
uploadOnSave: false,
passive: false,
debug: false,
privateKeyPath: null,
passphrase: null,
agent: null,
allow: [],
ignore: ["\\.vscode", "\\.git", "\\.DS_Store"],
pathMapping: {}, // <----- NEW LINE
...
getSyncConfig: function() {
let config = this.getConfig();
return {
getGeneratedDir: this.getGeneratedDir,
local: config.localPath,
root: config.rootPath,
remote: upath.toUnix(config.remotePath),
host: config.host,
port: config.port,
user: config.username,
password: config.password,
passphrase: config.passphrase,
allow: config.allow,
ignore: config.ignore,
pathMapping: config.pathMapping, // <----- NEW LINE
sync-helper.js
( C:\Users\<User>\.vscode\extensions\lukasz-wronski.ftp-sync-0.3.9\modules
)
var uploadFile = function(localPath, rootPath, callback) {
output(
getCurrentTime() +
" > [sync-helper] uploading: " +
path.parse(localPath).base
);
var remotePath = upath.toUnix(
path.join(ftpConfig.remote, localPath.replace(rootPath, ""))
);
var remoteDir = upath.toUnix(path.dirname(remotePath));
connect(function(err) {
if (err) {
callback(err);
return;
}
var putFile = function() {
ftp.put(localPath, remotePath, function(err) {
callback(err);
});
};
if (remoteDir != ".")
// <----- NEW CODE START
{
var noPathMapping = true;
for(var pathMappingPath in ftpConfig.pathMapping) {
if (remoteDir.includes(pathMappingPath)) {
noPathMapping = false;
remotePath = remotePath.replace("/"+pathMappingPath, "/"+ftpConfig.pathMapping[pathMappingPath])
ensureDirExists(upath.toUnix(path.dirname(remotePath)), function(err) {
if (err) callback(err);
else putFile();
});
}
}
if (noPathMapping)
// <----- NEW CODE END
ensureDirExists(remoteDir, function(err) {
if (err) callback(err);
else putFile();
});
}
else putFile();
});
};
Configuration Examples:
.vscode\ftp-sync.json
...
"pathMapping": {
"Public": "TheValue"
}
...
The above Example upload local Files from Folder Public
to remote Folder TheValue
.
...
"pathMapping": {
"Public": ""
}
...
The above Example upload local Files from Folder Public
to remote Folder Root ( Defined at remotePath
).
"remotePath": "./www/mysite/",
I know this Repo seems to be off but maybe somebody knows: Is there a way to upload Files to another Location then in the Local Folders ?
eg.: Files are here: Public/.whatever and on the Server it should be here: ./.whatever Without the "Public" Folder.
Is that possible ?