/// <summary> /// FtpInternalDownload() --> Performs an FTP Download. /// </summary> /// <param name="folder">Indicates the folder where the file will be uploaded</param> /// <param name="localfolders">Indicates the local folders where the file will be downloaded to</param> /// <param name="apps">Indicates the eFlow apps for which the download are going to be placed</param> /// <param name="hostname">Indicates the host name where the file will be uploaded</param> /// <param name="username">Indicates the name of the user allowed to login into the hostname</param> /// <param name="pwd">Indicates the password of the user allowed to login into the hostname</param> /// <example><code>s.FtpInternalDownload("/images_receive", localfolders, apps, "ftp.doksend.com", "supplierportaluser", "e7low5!!");</code></example> protected bool FtpInternalDownload(string folder, string[] localfolders, string[] apps, string hostname, string username, string pwd) { bool result = false; try { using (Chilkat.Ftp2 ftp = new Chilkat.Ftp2()) { if (ftp.UnlockComponent(Constants.cStrChilkatFtpLic)) { ftp.Hostname = hostname; ftp.Username = username; ftp.Password = pwd; ftp.Passive = true; if (ftp.Connect()) { if (ftp.ChangeRemoteDir(folder)) { ftp.ListPattern = Constants.cStrAllAll; for (int i = 0; i <= ftp.NumFilesAndDirs - 1; i++) { if (localfolders.Length > 0 && apps.Length > 0) { string fl = ftp.GetFilename(i); string lfn = GetLocalFolderFileName(fl, localfolders, apps); if (File.Exists(lfn)) { File.Delete(lfn); } result = ftp.GetFile(fl, lfn); Thread.Sleep(50); ftp.DeleteRemoteFile(fl); Thread.Sleep(50); } } } } else { Logging.WriteLog(ftp.LastErrorText); } ftp.Disconnect(); } } } catch (Exception ex) { Logging.WriteLog(ex.ToString()); } return(result); }
public static void DownloadFile(string FTPAddress, string Dir, string UN, string PW, string Filename) { Chilkat.Ftp2 ftp = new Chilkat.Ftp2(); bool success; // Any string unlocks the component for the 1st 30-days. success = ftp.UnlockComponent("RCKVGHFTP_hK0TOpsv6An5"); if (success != true) { Console.WriteLine(ftp.LastErrorText); return; } ftp.Hostname = FTPAddress; ftp.Username = UN; ftp.Password = PW; ftp.Passive = false; // The default data transfer mode is "Active" as opposed to "Passive". // Connect and login to the FTP server. success = ftp.Connect(); if (success != true) { Console.WriteLine(ftp.LastErrorText); return; } // Change to the remote directory where the file is located. // This step is only necessary if the file is not in the root directory // for the FTP account. success = ftp.ChangeRemoteDir(Dir); if (success != true) { Console.WriteLine(ftp.LastErrorText); return; } // Download a file. string localFilename = Filename; string remoteFilename = Filename; success = ftp.GetFile(remoteFilename, localFilename); if (success != true) { Console.WriteLine(ftp.LastErrorText); return; } ftp.Disconnect(); Console.WriteLine("File Downloaded!"); }
void m_bgWorker_DoWork(object sender, DoWorkEventArgs e) { // Indicate that we are in the background thread // The FTP object's event callback will need this. m_bgRunning = true; // We passed the filename as an argument. // However, we could've just as well accessed the filename // via the txtFilename textbox control. string filename = e.Argument as string; // Is this an upload or download? if (m_isUpload) { // This causes both AbortCheck and FtpPercentDone events to // fire. The callback methods are m_ftp_OnAbortCheck and // m_ftp_OnFtpPercentDone. These methods in turn call the // m_bgWorker.ReportProgress method, causing the // m_bgWorker_ProgressChanged to be called. The progress // bars can only be updated from a background thread // in the m_bgWorker_ProgressChanged event. The same applies // to any other Form controls. bool success = m_ftp.PutFile(filename, filename); e.Result = success; } else { bool success = m_ftp.GetFile(filename, filename); e.Result = success; } // Display the last-error and session log regardless of success/failure... m_ftpLastError = m_ftp.LastErrorText; m_ftpSessionLog = m_ftp.SessionLog; m_bgRunning = false; return; }