Click to See Complete Forum and Search --> : The remote server returned an error: (530) Not logged in.


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

toraj58
November 27th, 2008, 05:29 PM
i think the problem is here:
reqFTP.Credentials = new NetworkCredential(UserName, Password);

if the UserName you use is something like e.g. toraj58 and the domain of your site is something like mysite.com
i guess you have not qualified username with @.

then try this:

reqFTP.Credentials = New NetworkCredential("toraj58@mysite.com", "yourpassword")

smruti13
November 24th, 2010, 03:30 AM
Thanks man !!!!!! it resolved my problem. I was worrying what was going wrong but after reading this article i got it worked.