1

I have a file on my local machine.I want to use Upload File control of ASP.NET for uploading to other machine.This other machine is CentOS which was running on VMWare soft.

HTML

<body>
    <form id="form1" runat="server" enctype="multipart/form-data">
<asp:FileUpload ID="FileUpload1" runat="server" ToolTip="Select Only Excel File" />
 <asp:Button runat="server" ID="btnUpload" OnClick="btnUploadClick" Text="Upload" />
</form>

CODEBEHIND

public void ftpfile(string ftpfilepath, string inputfilepath)
        {
            ftpfilepath = "/jetnexus";
            string ftphost = "192.168.2.19";
            //here correct hostname or IP of the ftp server to be given
            string ftpfullpath = "ftp://" + ftphost + ftpfilepath;
            FtpWebRequest ftp = (FtpWebRequest)FtpWebRequest.Create(ftpfullpath);
            ftp.Credentials = new NetworkCredential("root", "jetnexus");
            //userid and password for the ftp server to given

            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();
        }
Brian
  • 163
  • 2
  • 18
  • Are you using webforms or mvc? and what have you tried so far? Once you upload the file to your asp.net server it seems straightforward. –  Mar 11 '13 at 09:39
  • I use webform.I tried to upload file from local machine to other machine.It didn't work anything. – Brian Mar 11 '13 at 10:12
  • People who downvote the questions, think twice. Just because downvoting randomly the OP will not be able to ask questions and he ll be banned from asking questions automatically. If the question is silly and easy to find by googling then suggest so. – Sakthivel Mar 11 '13 at 11:07
  • Did you get an error, and if so can you post it? Is your method that processes the FileUpload control and saves the file working (I.e., inputFilePath is confirmed to actually be the path of the file, and that file exists on the server after being uploaded?) And the FTP server is running on the other machine? I would rule all those things out to help isolate where the problem might be. – Dmitriy Khaykin Mar 11 '13 at 16:04
  • @codebrain: Dear brother,I think that it is not easy.Because I want to upload file from local to other machine.It is not mean upload file from this folder to other folder in same machine.Do you have any idea for resolve this issues?Thanks – Brian Mar 12 '13 at 03:16
  • @DavidKhaykin: Thanks you.I used CentOS in VMWare of other machine.I can show all of folder by FileZilla when I want to access to it.So,I want to upload file from my machine(Win7) to this machine(CentOS) – Brian Mar 12 '13 at 03:18
  • @BinhTieu i am supporting you. You have three downvotes in this question, i gave a upvote. Otherwise because of this downvoted question you will be banned from asking questions.. so i am helping you and telling others not to downvote your question :) see you had three downvotes and now only 1. sounds good ? – Sakthivel Mar 12 '13 at 06:03
  • It sound good.Thanks you,brother.I think that this question is not easy.Thanks brother again. – Brian Mar 12 '13 at 07:10
  • Check this link: http://www.codeproject.com/Articles/43091/Connect-to-a-UNC-Path-with-Credentials and this: http://stackoverflow.com/questions/3700871/connect-to-network-drive-with-user-name-and-password – codingbiz Mar 12 '13 at 15:29
  • http://www.codeproject.com/Articles/43091/Connect-to-a-UNC-Path-with-Credentials – Brian Mar 13 '13 at 05:24
  • I tried this link.But it didn't work,or I don't know what server name that I should typing.Okay,May we make a presentation by teamviwer.So that,I will show my screen for you.Thanks.Pls reply in here.Thanks – Brian Mar 13 '13 at 05:25
  • 1
    @BinhTieu Have you explained what the problem with your existing code is? Without lookign in detail, it seems to be going along the right lines. – Deanna Mar 13 '13 at 08:57
  • I fixed this issues by using winscp.Thanks all for reading. – Brian Mar 14 '13 at 02:54
  • I used http://winscp.net/eng/docs/library#csharp – Brian Mar 14 '13 at 02:55

0 Answers0