When uploading a directory, create directory only if it doesn't exist
@@ -363,13 +363,28 @@ impl FileTransferActivity {
}
}
FsEntry::Directory(dir) => {
- // Create directory on remote
+ // Check whether should create directory
+ if self.client.list_dir(remote_path.as_path()).is_err() {
match self.client.mkdir(remote_path.as_path()) {
Ok(_) => {
self.log(
LogLevel::Info,
format!("Created directory \"{}\"", remote_path.display()),
);
+ }
+ Err(err) => {
+ self.log_and_alert(
+ LogLevel::Error,
+ format!(
+ "Failed to create directory \"{}\": {}",
+ remote_path.display(),
+ err
+ ),
+ );
+ return;
+ }
+ }
+ }
// Get files in dir
match self.host.scan_dir(dir.abs_path.as_path()) {
Ok(entries) => {
@@ -380,11 +395,7 @@ impl FileTransferActivity {
break;
}
// Send entry; name is always None after first call
- self.filetransfer_send_recurse(
- &entry,
- remote_path.as_path(),
- None,
- );
+ self.filetransfer_send_recurse(&entry, remote_path.as_path(), None);
}
}
Err(err) => {
@@ -399,18 +410,6 @@ impl FileTransferActivity {
}
}
}
- Err(err) => {
- self.log_and_alert(
- LogLevel::Error,
- format!(
- "Failed to create directory \"{}\": {}",
- remote_path.display(),
- err
- ),
- );
- }
- }
- }
}
// Scan dir on remote
self.reload_remote_dir();
