Christel
November 25th, 2008, 02:35 PM
Hi,
I am trying to write a windows application in C# (Visual Studio 2008) that will pick up a file on an FPT with SSH server. I have connected to this server using WS FTP Pro and it worked fine. Here is the code I have written:
FileStream outputStream = new FileStream(Utility.GetNewFileName(), FileMode.Create);
FtpWebRequest reqFTP;
reqFTP = (FtpWebRequest)FtpWebRequest.Create(new Uri("ftp://" + ConfigurationManager.AppSettings["FTPServerName"] + ConfigurationManager.AppSettings["FTPFileName"]));
reqFTP.Method = WebRequestMethods.Ftp.DownloadFile;
reqFTP.UseBinary = true;
reqFTP.Proxy = null;
reqFTP.Credentials = new NetworkCredential(UserName, Password);
FtpWebResponse response = (FtpWebResponse)reqFTP.GetResponse();
Stream ftpStream = response.GetResponseStream();
long cl = response.ContentLength;
int bufferSize = 2048;
int readCount;
byte[] buffer = new byte[bufferSize];
readCount = ftpStream.Read(buffer, 0, bufferSize);
while (readCount > 0)
{
outputStream.Write(buffer, 0, readCount);
readCount = ftpStream.Read(buffer, 0, bufferSize);
}
ftpStream.Close();
outputStream.Close();
response.Close();
The line that is failing is: FtpWebResponse response = (FtpWebResponse)reqFTP.GetResponse();
The error returned is (530) Not Loggin in. I know those are the correct username and password because I can login with thos using the WS FTP Pro program and I can do it there.
I am new to FTP so hopefully someone can help me.
Thanks,
Christel
I am trying to write a windows application in C# (Visual Studio 2008) that will pick up a file on an FPT with SSH server. I have connected to this server using WS FTP Pro and it worked fine. Here is the code I have written:
FileStream outputStream = new FileStream(Utility.GetNewFileName(), FileMode.Create);
FtpWebRequest reqFTP;
reqFTP = (FtpWebRequest)FtpWebRequest.Create(new Uri("ftp://" + ConfigurationManager.AppSettings["FTPServerName"] + ConfigurationManager.AppSettings["FTPFileName"]));
reqFTP.Method = WebRequestMethods.Ftp.DownloadFile;
reqFTP.UseBinary = true;
reqFTP.Proxy = null;
reqFTP.Credentials = new NetworkCredential(UserName, Password);
FtpWebResponse response = (FtpWebResponse)reqFTP.GetResponse();
Stream ftpStream = response.GetResponseStream();
long cl = response.ContentLength;
int bufferSize = 2048;
int readCount;
byte[] buffer = new byte[bufferSize];
readCount = ftpStream.Read(buffer, 0, bufferSize);
while (readCount > 0)
{
outputStream.Write(buffer, 0, readCount);
readCount = ftpStream.Read(buffer, 0, bufferSize);
}
ftpStream.Close();
outputStream.Close();
response.Close();
The line that is failing is: FtpWebResponse response = (FtpWebResponse)reqFTP.GetResponse();
The error returned is (530) Not Loggin in. I know those are the correct username and password because I can login with thos using the WS FTP Pro program and I can do it there.
I am new to FTP so hopefully someone can help me.
Thanks,
Christel