hi all,
i am working on loading large files of size 200 mb or more sizes to one server to another but it gives Error
"The remote server returned an error: (550) File unavailable (e.g., file not found, no access)."
please help me my function to load files is
FTPUpload(string FilePath, string FTPServer, string Username, string Password)
(
//Reading file into a byte array
byte[] file = null;
file = System.IO.File.ReadAllBytes(p_FilePath);
//Request
System.Net.FtpWebRequest req = null;
req = (System.Net.FtpWebRequest)System.Net.WebRequest.Create(p_FTPServer);
//Credentials
System.Net.NetworkCredential credentials = new System.Net.NetworkCredential(p_Username, p_Password);
req.Credentials = credentials;
//Request Method
req.Method = System.Net.WebRequestMethods.Ftp.UploadFile;
//uploading file onto FTP server
System.IO.Stream stream = null;
stream = req.GetRequestStream();
stream.Write(file, 0, file.Length);
stream.Close();
)
please help..Thanks
Loading

Rasadul Alam RashedPosted Mar 25, 2013, 1:10 PM
.NET Framework does not support SFTP natively. We need to use a third party or open source component to do this. Some components are
SharpSSH example with source code: http://cybarlab.blogspot.com/2013/03/download-upload-files-form-sftp-server.html
Mai Hu NaPosted Mar 18, 2013, 1:27 AM
Rasadul Alam RashedPosted Mar 16, 2013, 7:57 AM
For this we need to include one namespace and it is. using System.Net
public void DownloadFile(string HostURL, string UserName, string Password, string SourceDirectory, string FileName, string LocalDirectory)
{
if (!File.Exists(LocalDirectory + FileName))
{
try
{
FtpWebRequest requestFileDownload = (FtpWebRequest)WebRequest.Create(HostURL + "/" + SourceDirectory + "/" + FileName);
requestFileDownload.Credentials = new NetworkCredential(UserName, Password);
requestFileDownload.Method = WebRequestMethods.Ftp.DownloadFile;
FtpWebResponse responseFileDownload = (FtpWebResponse)requestFileDownload.GetResponse();
Stream responseStream = responseFileDownload.GetResponseStream();
FileStream writeStream = new FileStream(LocalDirectory + FileName, FileMode.Create);
int Length = 2048;
Byte[] buffer = new Byte[Length];
int bytesRead = responseStream.Read(buffer, 0, Length);
while (bytesRead > 0)
{
writeStream.Write(buffer, 0, bytesRead);
bytesRead = responseStream.Read(buffer, 0, Length);
}
responseStream.Close();
writeStream.Close();
requestFileDownload = null;
responseFileDownload = null;
}
catch (Exception ex)
{
throw ex;
}
}
}
Here is more example for FTP operation.
http://cybarlab.com/download-upload-files-from-ftp-server-in-c-sharp