Note that there are some explanatory texts on larger screens.

plurals
  1. POC# - Download Directory - FTP
    text
    copied!<p>I'm trying to download a directory, using FTP in a C# application. I basically need to take a remote dir, and move it, and its contents into a local dir. </p> <p>Here is the function I'm currently using, and what the log output and errors are. The sample I'm referencing is for getting files, and possibly not directories:</p> <pre><code> private void Download(string file, string destination) { try { string getDir = "ftp://" + ftpServerIP + ftpPath + file + "/"; string putDir = destination + "\\" + file; Debug.WriteLine("GET: " + getDir); Debug.WriteLine("PUT: " + putDir); FtpWebRequest reqFTP; reqFTP = (FtpWebRequest)FtpWebRequest.Create (new Uri(getDir)); reqFTP.Credentials = new NetworkCredential(ftpUserID, ftpPassword); reqFTP.UseBinary = true; reqFTP.KeepAlive = false; reqFTP.Method = WebRequestMethods.Ftp.DownloadFile; reqFTP.Proxy = null; reqFTP.UsePassive = false; FtpWebResponse response = (FtpWebResponse)reqFTP.GetResponse(); Stream responseStream = response.GetResponseStream(); FileStream writeStream = new FileStream(putDir, FileMode.Create); int Length = 2048; Byte[] buffer = new Byte[Length]; int bytesRead = responseStream.Read(buffer, 0, Length); while (bytesRead &gt; 0) { writeStream.Write(buffer, 0, bytesRead); bytesRead = responseStream.Read(buffer, 0, Length); } writeStream.Close(); response.Close(); } catch (WebException wEx) { MessageBox.Show(wEx.Message, "Download Error"); } catch (Exception ex) { MessageBox.Show(ex.Message, "Download Error"); } } </code></pre> <p>Debug:</p> <pre><code>GET: ftp://I.P.ADDR/SOME_DIR.com/members/forms/THE_FOLDER_TO_GET/ PUT: C:\Users\Public\Documents\iMacros\Macros\THE_FOLDER_TO_WRITE A first chance exception of type 'System.Net.WebException' occurred in System.dll </code></pre> <p>MessageBox Output:</p> <pre><code>The requested URI is invalid for this FTP command. </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload