public List <string> ListFolder(string folderPath) { using (var client = new FluentFTP.FtpClient(env.FTP_HOST, new NetworkCredential(env.FTP_USERNAME, env.FTP_PASSWORD))) { return(new List <string>(client.GetNameListing(folderPath))); } }
public bool FolderExists(string folderPath) { using (var client = new FluentFTP.FtpClient(env.FTP_HOST, new NetworkCredential(env.FTP_USERNAME, env.FTP_PASSWORD))) { return(client.DirectoryExists(folderPath)); } }
public void DeleteFolder(string folderPath) { using (var client = new FluentFTP.FtpClient(env.FTP_HOST, new NetworkCredential(env.FTP_USERNAME, env.FTP_PASSWORD))) { client.DeleteDirectory(folderPath); } }
//private: FluentFTP.IFtpClient CreateFtpClient() { FluentFTP.IFtpClient ftpClient; if (m_cxnParam.Proxy != null) { var proxy = new FluentFTP.Proxy.ProxyInfo(); proxy.Host = m_cxnParam.Proxy.Host; proxy.Port = m_cxnParam.Proxy.Port; ftpClient = new FluentFTP.Proxy.FtpClientHttp11Proxy(proxy); ftpClient.Host = m_cxnParam.Host; ftpClient.DataConnectionType = FluentFTP.FtpDataConnectionType.PASV; } else { ftpClient = new FluentFTP.FtpClient(m_cxnParam.Host); } if (m_cxnParam.Credential != null) { ftpClient.Credentials = new NetworkCredential(m_cxnParam.Credential.UserName, m_cxnParam.Credential.Password); } return(ftpClient); }
internal static void ConfigureFtpClient(FluentFTP.FtpClient client) { client.Host = App.CurrentConfig.FtpAdress; client.Credentials = new System.Net.NetworkCredential(App.CurrentConfig.FtpUser, App.CurrentConfig.FtpPassw); client.ConnectTimeout = 30000; client.ReadTimeout = 30000; client.RetryAttempts = 10000; }
private async Task UploadFileAsync(FluentFTP.FtpClient client, string remotePath, StorageFile localFile, CancellationToken token, IProgress <double> progress) { await semaphore.WaitAsync(); try { string remoteDirectory = Path.GetDirectoryName(remotePath); string remoteFileName = Path.GetFileName(remotePath); while (!(await client.DirectoryExistsAsync(remoteDirectory))) { string dir = Path.GetFileName(remoteDirectory); remoteDirectory = Path.GetDirectoryName(remoteDirectory); remoteFileName = Path.Combine(dir, remoteFileName); } await client.SetWorkingDirectoryAsync(remoteDirectory); using (var stream = await localFile.OpenStreamForReadAsync()) { await client.UploadAsync(stream, remoteFileName, FluentFTP.FtpExists.Overwrite, true, token, progress); } } finally { client.Dispose(); semaphore.Release(); } }
private void Button1_Click(object sender, EventArgs e) { ServerFilesTree.Nodes.Clear(); FtpConnection = new FluentFTP.FtpClient(HostNameTextBox.Text); FtpConnection.Encoding = Encoding.UTF8; FtpConnection.ConnectTimeout = 10000; if (UsernameTextBox.Text != "") { FtpConnection.Credentials = new NetworkCredential(UsernameTextBox.Text, PasswordTextBox.Text); } try { FtpConnection.Connect(); } catch (Exception ex) { MessageBox.Show("Error Connecting"); MessageBox.Show("Error: \n " + ex.Message); return; } MessageBox.Show("Conected"); WorkingDirectory = "/"; ServerFilesTree.Nodes.Add("/"); ServerFilesTree.Nodes[0].Tag = "/"; foreach (FluentFTP.FtpListItem Item in FtpConnection.GetListing(WorkingDirectory)) { ServerFilesTree.Nodes[0].Nodes.Add(Item.FullName.Replace(WorkingDirectory, "")); ServerFilesTree.Nodes[0].LastNode.Tag = Item.FullName; //MessageBox.Show("Item Name: " + ServerFilesTree.Nodes[0].LastNode.Text); //MessageBox.Show("Item Tag: " + ServerFilesTree.Nodes[0].LastNode.Tag); } }
private void ConnectTo() { try { AddEditWindow addEditWindow = new AddEditWindow(); if (addEditWindow.model.ReturnCommand?.ToLower() == "ok") { if (client.IsConnected) { client.Disconnect(); } var customConfig = addEditWindow.model.SelectedItem; if (customConfig == null || !customConfig.CanTryConnect) { return; } client = new FluentFTP.FtpClient(customConfig.HostName, int.Parse(customConfig.Port), customConfig.UserName, customConfig.Password); client.Connect(); ListCombine(customConfig.RemoteFolder ?? ""); StatusText = "Connected"; } } catch (Exception exc) { ToolsLib.Tools.ExceptionLogAndShow(exc, "ConnectTo"); } }
public void UploadFile(string ftpPath, string filepath) { using (var client = new FluentFTP.FtpClient(env.FTP_HOST, new NetworkCredential(env.FTP_USERNAME, env.FTP_PASSWORD))) { client.UploadFile(filepath, ftpPath, createRemoteDir: true); } }
public void UploadBytes(string ftpPath, byte[] bytes) { using (var client = new FluentFTP.FtpClient(env.FTP_HOST, new NetworkCredential(env.FTP_USERNAME, env.FTP_PASSWORD))) { client.Upload(bytes, ftpPath, createRemoteDir: true); } }
public void MoveFolder(string folderPath, string destinationFolderPath) { using (var client = new FluentFTP.FtpClient(env.FTP_HOST, new NetworkCredential(env.FTP_USERNAME, env.FTP_PASSWORD))) { client.MoveDirectory(folderPath, destinationFolderPath); } }
public void changePermissions(string Path, string Permissions, string HostName, string UserName, string Password) { FluentFTP.FtpClient client = new FluentFTP.FtpClient(HostName); client.Credentials = new NetworkCredential(UserName, Password); client.Connect(); client.Chmod(Path, Convert.ToInt32(Permissions)); client.Disconnect(); }
public PlainFtpClient(string host, string userName, string password) : base(host, userName, password) { _client = new FluentFTP.FtpClient(host); if (!String.IsNullOrEmpty(_userName) && !String.IsNullOrEmpty(_password)) { _client.Credentials = new System.Net.NetworkCredential(_userName, _password); } }
public Interface.IStorage Build(string url) { var client = new FluentFTP.FtpClient(url); return(new FTPStorage { Client = client }); }
public void IndexServer() { using (var client = new FluentFTP.FtpClient(Server.HostName, Server.Port, Server.Login, Server.PassWord)) { ProcessFolderFiles(client, Server.StartingDir); } CleanUppFilesAndFolders(); }
public string DownloadString(string ftpPath) { using (var client = new FluentFTP.FtpClient(env.FTP_HOST, new NetworkCredential(env.FTP_USERNAME, env.FTP_PASSWORD))) { client.Download(out byte[] outBytes, ftpPath); return(Encoding.UTF8.GetString(outBytes)); } }
private static FluentFTP.FtpClient CloneFtpClient(FluentFTP.FtpClient client) { var newClient = new FluentFTP.FtpClient { Host = client.Host, Credentials = client.Credentials, DataConnectionType = client.DataConnectionType, Encoding = client.Encoding, EncryptionMode = client.EncryptionMode }; newClient.ValidateCertificate += FtpClient_ValidateCertificate; return(newClient); }
private FluentFTP.FtpClient GetFtpClient() { if (ftp == null) { ftp = new FluentFTP.FtpClient { Host = host, Credentials = new System.Net.NetworkCredential(user, password), }; } if (!ftp.IsConnected) { ftp.Connect(); } return(ftp); }
private async Task FtpConnectAsync(FluentFTP.FtpClient client) { var file = await ApplicationData.Current.TemporaryFolder.CreateFileAsync("log.log", CreationCollisionOption.OpenIfExists); FluentFTP.FtpTrace.LogToFile = file.Path; await client.ConnectAsync(); if (client.Capabilities.HasFlag(FluentFTP.FtpCapability.UTF8)) { client.Encoding = System.Text.Encoding.UTF8; } else { client.Encoding = preferredEncoding; } }
protected FluentFTP.FtpClient GetFtpClient() { if (_FtpClient == null) { _FtpClient = new FluentFTP.FtpClient { Host = _TargetFtp.Host, Port = _TargetFtp.Port, Credentials = new NetworkCredential(_TargetFtp.User, _TargetFtp.Password), RetryAttempts = 3, SocketKeepAlive = true }; } return(_FtpClient); }
static void TestClient() { string host = ConfigurationManager.AppSettings["FTP_HOST"]; int port = int.Parse(ConfigurationManager.AppSettings["FTP_PORT"]); string username = ConfigurationManager.AppSettings["FTP_USERNAME"]; string password = ConfigurationManager.AppSettings["FTP_PASSWORD"]; using (FileStream stream = File.Open("C:\\ftp.txt", FileMode.Open)) { FluentFTP.FtpClient client = new FluentFTP.FtpClient(host, port, username, password); client.Connect(); client.Upload(stream, $"/ftp.txt", FluentFTP.FtpExists.Overwrite, true); client.Disconnect(); stream.Close(); } }
public Interface.IStorage Build(string url, string username, string password) { if (username is null) { throw new ArgumentNullException(nameof(username)); } if (password is null) { throw new ArgumentNullException(nameof(password)); } var netCredential = new System.Net.NetworkCredential(username, password); var client = new FluentFTP.FtpClient(url, netCredential); return(new FTPStorage { Client = client }); }
public void runFluent(int command) { //0 = change permissions if (command == 0) { try { FluentFTP.FtpClient client = new FluentFTP.FtpClient(this.connection.ServerName); client.Credentials = new System.Net.NetworkCredential(this.connection.UserName, this.connection.PassWord); client.Connect(); client.Chmod(this.path, this.permission); client.Disconnect(); } catch (Exception e) { throw e; } } }
private void Connect() { try { if (ConfigData == null || !ConfigData.CanTryConnect) { return; } client = new FluentFTP.FtpClient(ConfigData.HostName, int.Parse(ConfigData.Port), ConfigData.UserName, ConfigData.Password); client.Connect(); ListCombine(ConfigData.RemoteFolder ?? ""); StatusText = "Connected"; ConfigData.LastUse = DateTime.Now; } catch (Exception) { MessageBox.Show("Can't connect"); } }
private async Task DownloadFileAsync(FluentFTP.FtpClient client, string remotePath, StorageFile localFile, CancellationToken token, IProgress <double> progress) { await semaphore.WaitAsync(); try { string remoteDirectory = Path.GetDirectoryName(remotePath); string remoteFileName = Path.GetFileName(remotePath); await client.SetWorkingDirectoryAsync(remoteDirectory); using (var stream = await localFile.OpenStreamForWriteAsync()) { await client.DownloadAsync(stream, remoteFileName, token, progress); } } finally { client.Dispose(); semaphore.Release(); } }
public void AddDownloadFile(FluentFTP.FtpClient client, string remotePath, StorageFile localFile, Action callBack) { client = CloneFtpClient(client); FtpJob job = new FtpJob(); var cts = new CancellationTokenSource(); var progress = new Progress <double>(x => { job.Progress = x; }); job.Task = DownloadFileAsync(client, remotePath, localFile, cts.Token, progress).ContinueWith(x => { if (!cts.IsCancellationRequested) { job.Progress = double.NaN; try { callBack(); } catch { } } if (x.IsCanceled) { job.Status = FtpJob.JobStatus.Cancelled; } else if (x.IsFaulted) { job.Status = FtpJob.JobStatus.Faulted; } else if (x.IsCompleted) { job.Status = FtpJob.JobStatus.Completed; } job.Exception = x.Exception; }); job.Name = string.Format("下载{0}", Path.GetFileName(remotePath)); job.CancellationTokenSource = cts; _jobs.Add(job); }
private void ProcessFolderFiles(FluentFTP.FtpClient client, String directory, Data.Models.FtpFolder parentFolder = null) { Data.Models.FtpFolder folder = null; lock (_locker) folder = folderList.FirstOrDefault(f => f.FullName == directory.Trim()); if (folder == null) { FtpFolderService.Create(folder = new Data.Models.FtpFolder { FullName = directory, ServerId = Server.Id, ShortName = GetDirectoryName(directory) ?? "", FolderId = parentFolder?.Id }); } else { folder.Modified = DateTime.Now; folder.FolderId = parentFolder?.Id; FtpFolderService.Update(folder); } var list = client.GetListing(directory); //cannot be done in parallel some servers might be limited to 1 connection per IP list.ForEach((item) => { if (item.Type == FluentFTP.FtpFileSystemObjectType.Directory) { ProcessFolderFiles(client, item.FullName, folder); } else if (item.Type == FluentFTP.FtpFileSystemObjectType.File) { ProcessFile(item, folder); } }); }
private FluentFTP.FtpClient CreateFtpClient(Uri address, System.Net.NetworkCredential credential, bool encrypt) { var client = new FluentFTP.FtpClient { Host = address.Host, Port = address.Port >= 0 ? address.Port : 21, Credentials = GetCredential(address.UserInfo), }; client.DataConnectionType = FluentFTP.FtpDataConnectionType.PASV; client.DownloadDataType = FluentFTP.FtpDataType.Binary; if (encrypt) { client.EncryptionMode = FluentFTP.FtpEncryptionMode.Explicit; client.ValidateCertificate += FtpClient_ValidateCertificate; } else { client.EncryptionMode = FluentFTP.FtpEncryptionMode.None; } return(client); }
static void SaveFileToFtp(string sessionId, string userId, string toSave, string extName) { string filename = ConfigurationManager.AppSettings["SSO_ROOT"] + sessionId; string host = ConfigurationManager.AppSettings["FTP_HOST"]; int port = int.Parse(ConfigurationManager.AppSettings["FTP_PORT"]); string username = ConfigurationManager.AppSettings["FTP_USERNAME"]; string password = ConfigurationManager.AppSettings["FTP_PASSWORD"]; string remoteRoot = ConfigurationManager.AppSettings["REMOTE_ROOT"]; using (FileStream stream = File.Open(filename, FileMode.Open)) { FluentFTP.FtpClient client = new FluentFTP.FtpClient(host, port, username, password); client.Connect(); client.Upload(stream, $"{remoteRoot}{userId}/{userId}_{toSave}_{DateTime.Now.ToString("yyyyMMddHHmmss")}.{extName}", FluentFTP.FtpExists.Overwrite, true); client.Disconnect(); stream.Close(); } File.Delete(filename); }
public static async Task <IActionResult> Run( [HttpTrigger(AuthorizationLevel.Anonymous, "get", "post", Route = null)] HttpRequest req, ILogger log) { log.LogInformation("C# HTTP trigger function processed a request."); try { var client = new FluentFTP.FtpClient("104.46.7.78", @"ftpuser2", "password"); // Change this value to a string of the path you would like to check for your user. My user name was AzrueUser var items = await client.GetListingAsync("/home/AzureUser"); foreach (var i in items) { log.LogInformation($"{i.Name} {i.Size}"); } } catch (Exception exc) { log.LogInformation(exc.Message); } string name = req.Query["name"]; string requestBody = await new StreamReader(req.Body).ReadToEndAsync(); dynamic data = JsonConvert.DeserializeObject(requestBody); name = name ?? data?.name; string responseMessage = string.IsNullOrEmpty(name) ? "This HTTP triggered function executed successfully. Pass a name in the query string or in the request body for a personalized response." : $"Hello, {name}. This HTTP triggered function executed successfully."; return(new OkObjectResult(responseMessage)); }