C# .NET - We are facing on random basis, User Not Logged in error code 530

Asked By Amit Choudhary on 17-Jun-11 10:22 AM

We are facing on random basis for same user name & pwd, The remote server returned an error: (530) Not logged in.
Please suggest , if we find any issue in below code :

public
bool FTPFile()

{

try

{

if (IsDirectoryExistAtRemote() == false)

CreateRemoteDirectory();

string URI = "ftp://" + FTPServer + "/" + DirectoryAtFTPServer + "/" + FileNameAtFTPServer;

FtpWebRequest ftpRequest = (FtpWebRequest)WebRequest.Create(URI);

try

{

// Create a Uri instance with the specified URI string.

// If the URI is not correctly formed, the Uri constructor

// will throw an exception.

ManualResetEvent waitObject;

string fileName = FileToFTP;

FtpState state = new FtpState();

ftpRequest.Method = WebRequestMethods.Ftp.UploadFile;

ftpRequest.Credentials = new NetworkCredential(FTPUsername, FTPPassword);

ftpRequest.Proxy = new WebProxy();

ftpRequest.ConnectionGroupName = "GroupName";

ftpRequest.KeepAlive = false;

// Store the request in the object that we pass into the

// asynchronous operations.

state.Request = ftpRequest;

state.FileName = fileName;

// Get the event to wait on.

waitObject = state.OperationComplete;

// Asynchronously get the stream for the file contents.

ftpRequest.BeginGetRequestStream(

new AsyncCallback(EndGetStreamCallback),

state

);

// Block the current thread until all operations are complete.

waitObject.WaitOne();

// The operations either completed or threw an exception.

if (state.OperationException != null)

{

FTPOperationStatus = ReportEnum.ExportStatus.Failed;

throw state.OperationException;

}

else

{

FTPOperationStatus = ReportEnum.ExportStatus.Finished;

return true;

}

}

finally

{

ftpRequest.ServicePoint.CloseConnectionGroup("GroupName");

}

}

catch (Exception ex)

{

FTPFailureDescription = ex.Message;

//FTPFailureDescription = ((FtpWebResponse)we.Response).StatusDescription;

FTPOperationStatus = ReportEnum.ExportStatus.Failed;

return false;

}


}

private bool IsDirectoryExistAtRemote()

{

FtpWebResponse response= null;

FtpWebRequest ftpRequest = null;

try

private

{

string URI = "ftp://" + FTPServer + "/" + DirectoryAtFTPServer;

ftpRequest = (FtpWebRequest)WebRequest.Create(URI);

ftpRequest.ConnectionGroupName = "GroupName";

ftpRequest.KeepAlive = false;

ftpRequest.Method = WebRequestMethods.Ftp.PrintWorkingDirectory;

ftpRequest.Credentials = new NetworkCredential(FTPUsername, FTPPassword);

ftpRequest.Proxy = new WebProxy();

ftpRequest.UseBinary = true;

response = ftpRequest.GetResponse() as FtpWebResponse;

return true;

}

catch (WebException ex)

{

response = (FtpWebResponse)ex.Response;

if (response.StatusCode == FtpStatusCode.ActionNotTakenFileUnavailable)

return false;

else

return true;

}

finally

{

ftpRequest.ServicePoint.CloseConnectionGroup("GroupName");

if (response!= null)

response.Close();

}

}

private bool CreateRemoteDirectory()

{

try

{

string URI = "ftp://" + FTPServer + "/" + DirectoryAtFTPServer;

FtpWebRequest ftpRequest = (FtpWebRequest)WebRequest.Create(URI);

ftpRequest.Method = WebRequestMethods.Ftp.MakeDirectory;

ftpRequest.Credentials = new NetworkCredential(FTPUsername, FTPPassword);

ftpRequest.Proxy = new WebProxy();

FtpWebResponse response = ftpRequest.GetResponse() as FtpWebResponse;

response.Close();

if (response.StatusCode == FtpStatusCode.PathnameCreated)

return true;

else

return false;

}

catch (WebException ex)

{

throw new Exception("Directory could not be created at remote location");

}

}

Jitendra Faye replied to Amit Choudhary on 17-Jun-11 10:31 AM

Please refer to the following link below for the information about "The remote server returned an error: (530) Not logged in.".

http://forums.msdn.microsoft.com/en-US/netfxnetcom/thread/45c82fdb-1a25-4913-9324-f5d468d4ad30/

hope this will help you.

Jitendra Faye replied to Amit Choudhary on 17-Jun-11 10:34 AM
i think the problem is here:


ftpRequest.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:

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