public override UploadResult Upload(Stream stream, string fileName) { UploadResult result = new UploadResult(); fileName = Helpers.GetValidURL(fileName); string path = Account.GetSubFolderPath(fileName); using (ftpClient = new FTP(Account, BufferSize)) { ftpClient.ProgressChanged += OnProgressChanged; try { IsUploading = true; ftpClient.UploadData(stream, path); } finally { IsUploading = false; } } if (!stopUpload && Errors.Count == 0) { result.URL = Account.GetUriPath(fileName); } return(result); }
public override UploadResult Upload(Stream stream, string fileName) { UploadResult result = new UploadResult(); fileName = Helpers.GetValidURL(fileName); string path = Account.GetSubFolderPath(fileName); using (ftpClient = new FTP(Account, BufferSize)) { ftpClient.ProgressChanged += OnProgressChanged; try { IsUploading = true; ftpClient.UploadData(stream, path); } finally { IsUploading = false; } } if (!stopUpload && Errors.Count == 0) { result.URL = Account.GetUriPath(fileName); } return result; }
public override UploadResult Upload(Stream stream, string fileName) { UploadResult result = new UploadResult(); string remotePath = GetRemotePath(fileName); try { stream.Position = 0; if (FTPAccount.Protocol == FTPProtocol.SFTP) { using (SFTP sftpClient = new SFTP(FTPAccount)) { if (!sftpClient.IsInstantiated) { Errors.Add("An SFTP client couldn't be instantiated, not enough information.\r\nCould be a missing key file."); } else { sftpClient.ProgressChanged += new Uploader.ProgressEventHandler(x => OnProgressChanged(x)); sftpClient.UploadData(stream, remotePath); } } } else // FTP or FTPS { using (FTP ftpClient = new FTP(FTPAccount)) { ftpClient.ProgressChanged += new Uploader.ProgressEventHandler(x => OnProgressChanged(x)); ftpClient.UploadData(stream, remotePath); } } } catch (Exception e) { DebugHelper.WriteException(e); Errors.Add(e.Message); } if (Errors.Count == 0) { result.URL = FTPAccount.GetUriPath(fileName); } return result; }
public override UploadResult Upload(Stream stream, string fileName) { UploadResult result = new UploadResult(); string remotePath = GetRemotePath(fileName); try { stream.Position = 0; if (FTPAccount.Protocol == FTPProtocol.SFTP) { using (SFTP sftpClient = new SFTP(FTPAccount)) { if (!sftpClient.IsInstantiated) { Errors.Add("An SFTP client couldn't be instantiated, not enough information.\r\nCould be a missing key file."); } else { sftpClient.ProgressChanged += new Uploader.ProgressEventHandler(x => OnProgressChanged(x)); sftpClient.UploadData(stream, remotePath); } } } else // FTP or FTPS { using (FTP ftpClient = new FTP(FTPAccount)) { ftpClient.ProgressChanged += new Uploader.ProgressEventHandler(x => OnProgressChanged(x)); ftpClient.UploadData(stream, remotePath); } } } catch (Exception e) { DebugHelper.WriteException(e); Errors.Add(e.Message); } if (Errors.Count == 0) { result.URL = FTPAccount.GetUriPath(fileName); } return(result); }