cancel
Showing results for 
Search instead for 
Did you mean: 

FTP Upload in SAP B1 -Time out Error

0 Kudos

Hello Friends,

My task is to upload a CSV file into a specified FTP loacation.But the system is throwing time out message from a line of the code. Please help me out on this issue.

  public static string UploadFile(string ftpUrl, string userName, string password, string uploadFTPDirectory, string localFilePath)

        {

            string PureFileName = new FileInfo(localFilePath).Name;

            String uploadUrl = String.Format("{0}{1}/{2}", ftpUrl, uploadFTPDirectory, PureFileName);

            //String uploadUrl = String.Format("{0}{1}", ftpUrl, uploadFTPDirectory);

            FtpWebRequest ftpRequest = (FtpWebRequest)FtpWebRequest.Create(uploadUrl);

            ftpRequest.Proxy =null;

            ftpRequest.Method = WebRequestMethods.Ftp.UploadFile;

            ftpRequest.Credentials = new NetworkCredential(userName, password);

            ftpRequest.UseBinary = true;

            ftpRequest.UsePassive = false;

            try

            {

                byte[] fileData = File.ReadAllBytes(localFilePath);

                ftpRequest.ContentLength = fileData.Length;

                using (Stream fileStream = ftpRequest.GetRequestStream())

                {

                    fileStream.Write(fileData, 0, fileData.Length);

                    fileStream.Close();

                }

                using (FtpWebResponse ftpResponse = (FtpWebResponse)ftpRequest.GetResponse())----------'Sytem throws the Timed out Message here.'

                {

                    return ftpResponse.StatusDescription;

                }

            }

            catch(WebException e)

            {

               string s = ((FtpWebResponse)e.Response).StatusDescription;

               return s;

            }

        }

With thanks and Regards,

Rajeev M Kartha

Accepted Solutions (1)

Accepted Solutions (1)

frank_wang6
Active Contributor
0 Kudos

I dont know why you posted this here. but you might want to disable firewall.

FTP does require two ports to work 20, and 21.

Frank

0 Kudos

Thank you frank... i got the problem solved the next day i posted the question. As you said , i had to disable the firewall..

Answers (0)