I want to write a program that using FTP to upload files into server.
But I cannot get the path from client to upload.
How can I get client's path to upload files into my FTP server?
Also, I would like to know what is the different between FileUpload1.FileName and FileUpload1.PostedFile.FileName ?
Thanks a lot!
my coding here...
protected void Button1_Click(object sender, EventArgs e)
{
for (int p = 0; p < Request.Files.Count; p++)
{
HttpPostedFile PostedFile = Request.Files[p];
if (PostedFile.ContentLength > 0)
{
string uploadName = PostedFile.FileName;
string fileName = System.IO.Path.GetFileName(PostedFile.FileName);
string path = Path.GetFileName(FileUpload1.FileName);
ftpfile(@"/wwwroot/CSSite/Uploads/aaa.rar", @"\\TOM-\Users\Public\Documents\Tr2.rar");
// ftpfile(@"/wwwroot/CSSite/Uploads/" + fileName, @"" + path + "/" + uploadName);
}
}
}
public void ftpfile(string ftpfilepath, string inputfilepath)
{
string ftphost = "127.0.0.1";
string ftpfullpath = "ftp://" + ftphost + ftpfilepath;
FtpWebRequest ftp = (FtpWebRequest)FtpWebRequest.Create(ftpfullpath);
ftp.Credentials = new NetworkCredential("id", "pwd");
ftp.Proxy = new WebProxy();
ftp.KeepAlive = true;
ftp.UseBinary = true;
ftp.Method = WebRequestMethods.Ftp.UploadFile;
FileStream fs = File.OpenRead(inputfilepath);
byte[] buffer = new byte[fs.Length];
fs.Read(buffer, 0, buffer.Length);
fs.Close();
Stream ftpstream = ftp.GetRequestStream();
ftpstream.Write(buffer, 0, buffer.Length);
ftpstream.Close();
}
}
I've tried to use VS2008 and set the breakpoint, it can functionally work. (get the full path from client side, and upload successfully)
However, when I deploy the coding into IIS in the same machine, it shows error that cannot find the path like C:\Windows\System32\(myDoc).extension
but actually my upload path was (for example: C:\Users\Tom320\Documents\(myDoc).extension)
Thank you !