I've got a problem when uploading files to my FTP server. This connection usually works fine over a local connection - however, im trying to connect to the Public IP address of a system (ftp://xx.xxx.xxx.xx). I can connect to it just fine over filezilla to upload and download files - however, for some reason this just does not seem to work.
This is the code im using to create the WebRequest:
FtpWebRequest request = (FtpWebRequest)WebRequest.Create("ftp://xx.xxx.xx.xxx" + uploadPath);
request.UseBinary = true;
request.KeepAlive = false;
request.Method = WebRequestMethods.Ftp.UploadFile;
That runs fine in debug mode, all the filepaths are allowed, etc.. However, the code is throwing an error in this section here:
byte[] b = File.ReadAllBytes(tarPath);
request.ContentLength = b.Length;
using (Stream s = request.GetRequestStream())
{
s.Write(b, 0, b.Length);
}
FtpWebResponse ftpResp = (FtpWebResponse)request.GetResponse();
if (ftpResp != null)
{
Debug.WriteLine(ftpResp.StatusDescription);
}
Any Ideas? I've searched through the various online posts about this error and most of them are in regards to HTTPWebRequest, not FTPWebRequest. So if this code works over a local connection, then why is it acting like this over a global connection?
Thanks in advance
EDIT As requested, i've enabled network logging and here is the output - Bare in mind i've changed our public Server IP to 00x000x00x000 for security reasons and that is not an error ! :)
System.Net Information: 0 : [7120] FtpWebRequest#35287174::.ctor(ftp://00.000.00.000/users/be83dec5d120c42a6b94/119ab9d171cce2528d9a.tar)
System.Net Information: 0 : [7120] FtpWebRequest#35287174::GetRequestStream(Method=STOR.)
System.Net Information: 0 : [7120] Current OS installation type is 'Client'.
System.Net Information: 0 : [7120] RAS supported: True
System.Net Error: 0 : [7120] Can't retrieve proxy settings for Uri 'ftp://00.000.00.000/users/be83dec5d120c42a6b94/119ab9d171cce2528d9a.tar'. Error code: 12180.
System.Net Information: 0 : [7120] FtpControlStream#10261382 - Created connection from 192.168.0.48:15275 to 00.000.00.000:21.
System.Net Information: 0 : [7120] Associating FtpWebRequest#35287174 with FtpControlStream#10261382
System.Net Information: 0 : [7120] FtpControlStream#10261382 - Received response [220 (vsFTPd 3.0.2)]
System.Net Information: 0 : [7120] FtpControlStream#10261382 - Sending command [USER dev]
System.Net Information: 0 : [7120] FtpControlStream#10261382 - Received response [331 Please specify the password.]
System.Net Information: 0 : [7120] FtpControlStream#10261382 - Sending command [PASS ********]
System.Net Information: 0 : [7120] FtpControlStream#10261382 - Received response [230 Login successful.]
System.Net Information: 0 : [7120] FtpControlStream#10261382 - Sending command [OPTS utf8 on]
System.Net Information: 0 : [7120] FtpControlStream#10261382 - Received response [200 Always in UTF8 mode.]
System.Net Information: 0 : [7120] FtpControlStream#10261382 - Sending command [PWD]
System.Net Information: 0 : [7120] FtpControlStream#10261382 - Received response [257 "/home/dev"]
System.Net Information: 0 : [7120] FtpControlStream#10261382 - Sending command [TYPE I]
System.Net Information: 0 : [7120] FtpControlStream#10261382 - Received response [200 Switching to Binary mode.]
System.Net Information: 0 : [7120] FtpControlStream#10261382 - Sending command [PASV]
System.Net Information: 0 : [7120] FtpControlStream#10261382 - Received response [227 Entering Passive Mode (58,104,53,147,24,79).]
System.Net Information: 0 : [7120] FtpControlStream#10261382 - Sending command [STOR users/be83dec5d120c42a6b94/119ab9d171cce2528d9a.tar]
System.Net Information: 0 : [7120] FtpControlStream#10261382 - Received response [150 Ok to send data.]
System.Net Information: 0 : [5756] ServicePoint#22597652 - Closed as idle.
System.Net Information: 0 : [7120] FtpWebRequest#35287174::(Releasing FTP connection#10261382.)
System.Net Error: 0 : [7120] Exception in AppDomain#4032828::UnhandledExceptionHandler - The underlying connection was closed: An unexpected error occurred on a receive..
at System.Net.FtpWebRequest.SyncRequestCallback(Object obj)
at System.Net.FtpWebRequest.RequestCallback(Object obj)
at System.Net.CommandStream.Dispose(Boolean disposing)
at System.IO.Stream.Close()
at System.IO.Stream.Dispose()
at System.Net.ConnectionPool.Destroy(PooledStream pooledStream)
at System.Net.ConnectionPool.PutConnection(PooledStream pooledStream, Object owningObject, Int32 creationTimeout, Boolean canReuse)
at System.Net.FtpWebRequest.FinishRequestStage(RequestStage stage)
at System.Net.FtpWebRequest.SyncRequestCallback(Object obj)
at System.Net.FtpWebRequest.RequestCallback(Object obj)
at System.Net.CommandStream.Abort(Exception e)
at System.Net.CommandStream.CheckContinuePipeline()
at System.Net.FtpWebRequest.DataStreamClosed(CloseExState closeState)
at System.Net.FtpDataStream.System.Net.ICloseEx.CloseEx(CloseExState closeState)
at System.Net.FtpDataStream.Dispose(Boolean disposing)
at System.IO.Stream.Close()
at System.IO.Stream.Dispose()
at tcpClient.ftpClass.upload(String tarPath, String uploadPath) in c:\Users\Adam\Desktop\Project\Workspace\Network\SafeSpotService\SafeSpotClient\SafeSpotClient\ftpClass.cs:line 84
at SafeSpotClient.Service1.checkInCycle(String macAddr) in c:\Users\Adam\Desktop\Project\Workspace\Network\SafeSpotService\SafeSpotClient\SafeSpotClient\Service1.cs:line 121
at SafeSpotClient.Service1.Callback(Object state) in c:\Users\Adam\Desktop\Project\Workspace\Network\SafeSpotService\SafeSpotClient\SafeSpotClient\Service1.cs:line 168
at System.Threading.TimerQueueTimer.CallCallbackInContext(Object state)
at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.TimerQueueTimer.CallCallback()
at System.Threading.TimerQueueTimer.Fire()
at System.Threading.TimerQueue.FireNextTimers()
at System.Threading.TimerQueue.AppDomainTimerCallback()