Click here to Skip to main content
15,892,199 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a image file and I want to transfer it to a shared folder. I know how to do it through ftpserver............ But I don't know how to do it without FTP server address

What I have tried:

C#
reqFTP = (FtpWebRequest)FtpWebRequest.Create(new Uri("ftp://" + ftpServerIP + "/" + dir1 + "/" + dir2 + "/" +DateTime.Now.ToString("dd-MM-yyyy")));
                reqFTP.Method = WebRequestMethods.Ftp.MakeDirectory;

                reqFTP.UseBinary = true;
                reqFTP.Credentials = new NetworkCredential(ftpUserID, ftpPassword);
                FtpWebResponse response = (FtpWebResponse)reqFTP.GetResponse();
                Stream ftpStream = response.GetResponseStream();

                ftpStream.Close();
                response.Close();" 
..........." Stream strm = reqFTP.GetRequestStream();

                // Read from the file stream 2kb at a time
                contentLen = fs.Read(buff, 0, buffLength);

                // Till Stream content ends
                while (contentLen != 0)
                {
                    // Write Content from the file stream to the FTP Upload Stream
                    strm.Write(buff, 0, contentLen);
                    contentLen = fs.Read(buff, 0, buffLength);
                }

            
                strm.Close();
                fs.Close();"
Posted
Updated 27-Feb-18 3:27am
v2
Comments
Richard MacCutchan 27-Feb-18 6:44am    
Question makes no sense. How can you send a file to an FTP server without going through the server?

1 solution

Something like this:
rem *****************************************************
rem Robocopy from network share
rem *****************************************************
IF NOT EXIST "C:\Test" MD "C:\Test"
net use \\1.2.3.4\TestShare /user:username password 
ROBOCOPY \\1.2.3.4\TestShare C:\Test /S /SEC /V /NDL /NP /NFL /R:4 /W:15 
NET USE \\1.2.3.4\TestShare /DELETE
If you are wondering why ROBOCOPY is used in this DOS batchfile, that's because it is more reliable than a normal COPY, networks can be unreliable and ROBOCOPY can cope with this.
 
Share this answer
 
v2
Comments
Richard MacCutchan 27-Feb-18 9:36am    
Nice, but it's not C#.
RickZeeland 27-Feb-18 9:40am    
Correct, it's a DOS batch file !
But you could use Process.Start() to start it from C# if you want ...

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900