通过c#.net将文件传输到共享文件夹 [英] Transfer a file to a shared folder through c#.net

查看:181
本文介绍了通过c#.net将文件传输到共享文件夹的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个图像文件,我想将其传输到共享文件夹。我知道怎么做通过ftpserver ............但我不知道怎么做没有FTP服务器地址



我尝试了什么:



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:

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();"

推荐答案

这样的事情:

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

如果你想知道为什么在这个DOS批处理文件中使用了ROBOCOPY,那是因为它比普通COPY更可靠,网络可能不可靠,而且ROBOCOPY可以解决这个问题。

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.


这篇关于通过c#.net将文件传输到共享文件夹的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆