FTP - fIle upload problem
Hi, I am trying to upload a file to FTP server using fTPWebRequest. I need to upload the file with a temporary name forEx: ABC. TMP and once the file is completely/successfully uploaded I need to rename the file to ABC.ZIP. Could you please suggest any suitable/better method to achieve the same. Please find the code snippet i am using as below: Public void FTP (){ bool result = false; result = fm.ftpFiles(fileInf,strCMISLocation,tempObj); if (result) { fm.renameFtpedFile(fileInf.Name.Substring(0,fileInf.Name.Length -4)+".TMP",fileInf.Name,strCMISLocation);} else { }}private void renameFtpedFile(string oldName, string newName, string strCMISLocation) { FileManager fm = new FileManager(); FtpWebRequest reqFtp; reqFtp = (FtpWebRequest)FtpWebRequest.Create(new Uri(strCMISLocation + oldName)); reqFtp.Credentials = new NetworkCredential("TEST", "TEST"); reqFtp.KeepAlive = true; reqFtp.Method = WebRequestMethods.Ftp.Rename; reqFtp.RenameTo = newName; reqFtp.UseBinary = true; FtpWebResponse response = (FtpWebResponse)reqFtp.GetResponse(); Stream ftpStream = response.GetResponseStream(); ftpStream.Close(); response.Close(); } private bool ftpFiles(FileInfo fileInf, string strCMISLocation,ObjectList objZipFile) { int buffLength = Convert.ToInt32(fileInf.Length); FileManager fm = new FileManager(); byte[] buff = new byte[buffLength]; FtpWebRequest reqFTP; reqFTP = (FtpWebRequest)FtpWebRequest.Create(new Uri(strCMISLocation + fileInf.Name.Substring(0,fileInf.Name.Length -4)+".TMP")); reqFTP.Credentials = new NetworkCredential("TEST", "TEST"); reqFTP.KeepAlive = true; reqFTP.Method = WebRequestMethods.Ftp.UploadFile; reqFTP.UseBinary = true; reqFTP.ContentLength = fileInf.Length; int contentLen; FileStream fs = fileInf.OpenRead(); try { Stream strm = reqFTP.GetRequestStream(); contentLen = fs.Read(buff, 0, buffLength); while (contentLen != 0) { strm.Write(buff, 0, contentLen); contentLen = fs.Read(buff, 0, buffLength); }strm.Close(); fs.Close(); return true; } catch (Exception ex) { return false; } return false; }Thanks,Saket
July 22nd, 2009 8:58am

Hi, As this issue is related to scripting, I suggest discussing it in our MSDN forum. They mainly deal with scripting/coding issues and should be the best resource to troubleshoot this issue. http://social.msdn.microsoft.com/forums/en-US/categories/ I hope your issue can be resolved soon. Tim Quan - MSFT
Free Windows Admin Tool Kit Click here and download it now
July 22nd, 2009 9:57am

Ok Thanx
July 22nd, 2009 2:25pm

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics