FTPサーバーからファイルをダウンロードしてDBで指定されたネットワークドライブの場所に保存するWindowsサービスアプリケーションを実装しようとしています。ネットワーク共有フォルダは「Everyone」へのフルアクセスを許可します
bool status = true;
string webError = string.Empty;
FtpWebResponse response = null;
Stream ftpStream = null;
FileStream outputStream = null;
FtpDownloadToFolder = @"\\servername\SharedFolder\";
fileName = "test.jpg";
FtpWebRequest reqFTP = WebRequest.Create(new Uri(FtpAddress + "/" + fileName)) as FtpWebRequest;
reqFTP.Credentials = new NetworkCredential(FtpUser, FtpPassword);
reqFTP.Method = WebRequestMethods.Ftp.DownloadFile;
reqFTP.UseBinary = true;
reqFTP.Timeout = FtpTimeout;
response = reqFTP.GetResponse() as FtpWebResponse;
ftpStream = response.GetResponseStream();
if (!FtpDownloadToFolder.EndsWith("\\"))
{
FtpDownloadToFolder = FtpDownloadToFolder + "\\";
}
outputStream = new FileStream(FtpDownloadToFolder + "/" + fileName, FileMode.Create);
long cl = response.ContentLength;
int bufferSize = 2048;
byte[] buffer = new byte[bufferSize];
int readCount = ftpStream.Read(buffer, 0, bufferSize);
while (readCount > 0)
{
outputStream.Write(buffer, 0, readCount);
readCount = ftpStream.Read(buffer, 0, bufferSize);
}
そこで、ここではFTPサーバーからネットワークドライブにファイルをダウンロードしようとしています。しかし、次のエラーが発生します。
Access to the path '\\servername\SharedFolder\test.jpg' is denied.
System.Net.WebException: The remote server returned an error: 150 0.066 seconds (measured here), 3.78 Mbytes per second
---> System.IO.IOException: The operation is not allowed on non-connected sockets.
at System.Net.Sockets.NetworkStream.InitNetworkStream(Socket socket, FileAccess Access)
at System.Net.Sockets.NetworkStream..ctor(Socket socket, Boolean ownsSocket)
at System.Net.FtpControlStream.QueueOrCreateFtpDataStream(Stream& stream)
at System.Net.FtpControlStream.PipelineCallback(PipelineEntry entry, ResponseDescription response, Boolean timeout, Stream& stream)
at System.Net.CommandStream.PostReadCommandProcessing(Stream& stream)
at System.Net.CommandStream.PostSendCommandProcessing(Stream& stream)
at System.Net.CommandStream.ContinueCommandPipeline()
at System.Net.CommandStream.CheckContinuePipeline()
--- End of inner exception stack trace ---
at System.Net.FtpWebRequest.CheckError()
at System.Net.FtpWebRequest.SyncRequestCallback(Object obj)
at System.Net.CommandStream.Abort(Exception e)
at System.Net.CommandStream.CheckContinuePipeline()
at System.Net.FtpDataStream.System.Net.ICloseEx.CloseEx(CloseExState closeState)
at System.Net.FtpDataStream.Dispose(Boolean disposing)
at System.IO.Stream.Close()
at System.Net.FtpWebResponse.Close()
ここで何かが足りませんか?FTPサーバーからネットワーク共有フォルダーにファイルをコピーするにはどうすればよいですか?