Our Products:   CompleteFTP  edtFTPnet/Free  edtFTPnet/PRO  edtFTPj/Free  edtFTPj/PRO
+1 vote
2.5k views
in .NET FTP by (130 points)
edited by
I am trying to upload files in a winforms application (c# dotnet 4.6)

My code is very simple :

using (FTPConnection ftpConnection = new FTPConnection())
{
                        ftpConnection.ServerAddress = _ftpDefinition.Host;
                        ftpConnection.ServerPort = _ftpDefinition.Port;
                        ftpConnection.UserName = _ftpDefinition.UserName;
                        ftpConnection.Password = _ftpDefinition.PassWord;

                        FTPConnection.LogLevel = EnterpriseDT.Util.Debug.LogLevel.All;
                        FTPConnection.LogFile = @"C:\test\ftplog\ftp_log.txt";
 
                        ftpConnection.Connect();
                        ftpConnection.ChangeWorkingDirectory(remoteDir);
                        ftpConnection.UploadFile(localDir + fileName, fileName);
                        ftpConnection.Close();
}

From what I read in the logfile it looks like if the file has been transferred.
But if I look at the folder using an ftpclient (filezilla and Total Commander) then the file is not there.

Both FTP Clients cannot see it.
What can cause this and how to fix it ?

 

The entire log is here :

DEBUG [FTPConnection] 3 mei 2017 10:14:24.601 : Set LocalDirectory='C:\Development\Palm\gttXMLImportExportService\gttXMLImportExportService\gttXMLImportExportService\bin\Debug'
DEBUG [FTPClient] 3 mei 2017 10:14:24.601 : Connecting to ftp.dinetxs.com:10021
DEBUG [HostNameResolver] 3 mei 2017 10:14:24.601 : Resolving ftp.dinetxs.com
DEBUG [HostNameResolver] 3 mei 2017 10:14:24.611 : ftp.dinetxs.com resolved to 212.140.163.240
INFO [BaseSocket] 3 mei 2017 10:14:24.611 : Connecting to 212.140.163.240:10021 with timeout 120000 ms
DEBUG [BaseSocket] 3 mei 2017 10:14:24.661 : Successfully connected to 212.140.163.240:10021
DEBUG [FTPControlSocket] 3 mei 2017 10:14:24.661 : Setting socket timeout=120000
INFO [FTPControlSocket] 3 mei 2017 10:14:24.661 : Command encoding=System.Text.SBCSCodePageEncoding
DEBUG [FTPControlSocket] 3 mei 2017 10:14:24.661 : StrictReturnCodes=False
DEBUG [FTPControlSocket] 3 mei 2017 10:14:24.711 : 220 Welcome to the DINET FTP Server.
DEBUG [FTPConnection] 3 mei 2017 10:14:24.711 : Connected to ftp.dinetxs.com (instance=0)
DEBUG [FTPControlSocket] 3 mei 2017 10:14:24.711 : ---> USER OMSFTP201
DEBUG [FTPControlSocket] 3 mei 2017 10:14:24.761 : 331 Now please specify password.
DEBUG [FTPControlSocket] 3 mei 2017 10:14:24.761 : ---> PASS ********
DEBUG [FTPControlSocket] 3 mei 2017 10:14:24.891 : 230 Welcome to the EPIC FTP service.
DEBUG [FTPConnection] 3 mei 2017 10:14:24.891 : Successfully logged in
INFO [FTPConnection] 3 mei 2017 10:14:24.891 : Auto FEAT disabled
DEBUG [FTPControlSocket] 3 mei 2017 10:14:24.891 : ---> TYPE I
DEBUG [FTPControlSocket] 3 mei 2017 10:14:24.941 : 200 Ok.
DEBUG [FTPControlSocket] 3 mei 2017 10:14:24.941 : ---> PWD
DEBUG [FTPControlSocket] 3 mei 2017 10:14:24.991 : 257 "/"
DEBUG [FTPConnection] 3 mei 2017 10:14:26.210 : ChangeWorkingDirectory('/In')
DEBUG [FTPControlSocket] 3 mei 2017 10:14:26.210 : ---> CWD /In
DEBUG [FTPControlSocket] 3 mei 2017 10:14:26.260 : 250 Current directory is now /In.
DEBUG [FTPControlSocket] 3 mei 2017 10:14:26.260 : ---> PWD
DEBUG [FTPControlSocket] 3 mei 2017 10:14:26.310 : 257 "/In"
DEBUG [FTPConnection] 3 mei 2017 10:14:28.441 : UploadFile(\\TS2012R2\PalmDocuments\EDI\Ford\GttToFord\temp\GTT_20170503_33078_3.EDI,GTT_20170503_33078_3.EDI,False)
DEBUG [FTPConnection] 3 mei 2017 10:14:28.441 : Cancel resume
DEBUG [FTPControlSocket] 3 mei 2017 10:14:28.441 : ---> REST 0
DEBUG [FTPControlSocket] 3 mei 2017 10:14:28.491 : 502 This command is not implemented on this server.
DEBUG [FTPControlSocket] 3 mei 2017 10:14:28.491 : Expected reply codes = [350] (strict=False)
DEBUG [FTPClient] 3 mei 2017 10:14:28.491 : REST failed which is ok (This command is not implemented on this server. (code=502))
DEBUG [FTPControlSocket] 3 mei 2017 10:14:28.491 : ---> PASV
DEBUG [FTPControlSocket] 3 mei 2017 10:14:28.571 : 227 (212,140,163,240,117,130)
DEBUG [FTPControlSocket] 3 mei 2017 10:14:28.571 : Server supplied address=212.140.163.240
DEBUG [FTPControlSocket] 3 mei 2017 10:14:28.571 : Server supplied port=30082
DEBUG [FTPControlSocket] 3 mei 2017 10:14:28.571 : autoPassiveIPSubstitution=True
DEBUG [FTPControlSocket] 3 mei 2017 10:14:28.571 : remoteAddr=212.140.163.240
DEBUG [FTPControlSocket] 3 mei 2017 10:14:28.571 : Substituting server supplied IP (212.140.163.240) with remote host IP (212.140.163.240)
DEBUG [FTPControlSocket] 3 mei 2017 10:14:28.571 : NewPassiveDataSocket(212.140.163.240,30082)
INFO [BaseSocket] 3 mei 2017 10:14:28.571 : Connecting to 212.140.163.240:30082 with timeout 120000 ms
DEBUG [BaseSocket] 3 mei 2017 10:14:28.621 : Successfully connected to 212.140.163.240:30082
DEBUG [FTPControlSocket] 3 mei 2017 10:14:28.621 : Connected
DEBUG [FTPControlSocket] 3 mei 2017 10:14:28.621 : ---> STOR GTT_20170503_33078_3.EDI
DEBUG [FTPControlSocket] 3 mei 2017 10:14:28.701 : 125 Data connection connected, starting transfer.
DEBUG [FTPClient] 3 mei 2017 10:14:28.701 : Closing source stream
DEBUG [FTPClient] 3 mei 2017 10:14:28.701 : Transferred 2304 bytes to remote host
DEBUG [FTPControlSocket] 3 mei 2017 10:14:28.801 : 226 Ok.
DEBUG [FTPConnection] 3 mei 2017 10:14:29.650 : Closing connection (instance=0)
DEBUG [FTPFileFactory] 3 mei 2017 10:14:29.650 : Defaulting to Unix parsing
DEBUG [FTPControlSocket] 3 mei 2017 10:14:29.650 : ---> QUIT
DEBUG [FTPControlSocket] 3 mei 2017 10:14:29.700 : 221 Service is closing.
by (161k points)
Filezilla does cache directory listings, so make sure you close it and restart. Also ensure the file is going to the location you think it is.
by (130 points)
I do close the connection in filezilla before retrieving a list so that should not be the problem. If I drag the file from explorer to filezilla than I can see that file, but not the file that is uploaded using this library. As for the location, I do see the correct changedir in the log file. I will upload the entire log.
by (130 points)
I also tried with actually closing and restarting filezilla, still no changes. The file is still not there or not visible but the log keeps saying it has transferred the file.
by (130 points)
I also tried with Total Commander and the same result. The log says the file is transfered, but both Total Commander and FileZilla cannot see it

1 Answer

0 votes
by (51.1k points)
I'm sorry, but this is clearly a server issue.  Please contact the vendor of the server software.
by (140 points)
objFtp ==> is edtFTP component object

My program is as follow:
     //Check changedirectory to correct directory
             MainFTP.objWriteFileLog.DebugWrite("step 6_ChangeWorkingDirectory Before?Server??? = {objFtp.ServerDirectory}?MainFTP.vFTP_PARA[16] = {MainFTP.vFTP_PARA[16]}", MainFTP.sMsgGUID);
              objFtp.ChangeWorkingDirectory(MainFTP.vFTP_PARA[16]); ==> only change to MainFTP.vFTP_PARA[16] = /dw/ftpdata/ftpucc1/upload  

                             MainFTP.objWriteFileLog.DebugWrite("DO_FTP.doSend_FTP()", $"step 6_ChangeWorkingDirectory AFTER?Server??? = {objFtp.ServerDirectory}", MainFTP.sMsgGUID);

  MainFTP.objWriteFileLog.DebugWrite("DO_FTP.doSend_FTP()", $"step 7_UploadFile Before?Server???:{objFtp.ServerDirectory}?UploadFile:MainFTP.sBufSendName={MainFTP.sBufSendName.ToString()}", MainFTP.sMsgGUID);                                 
                                     objFtp.UploadFile(sMainFilePath + MainFTP.sBufSendName.ToString(), MainFTP.sBufSendName.ToString());                            
                                     MainFTP.objWriteFileLog.DebugWrite("DO_FTP.doSend_FTP()", $"7_UploadFile AFTER?Server???:{objFtp.ServerDirectory}", MainFTP.sMsgGUID);

=================

detail as up message (you can check the program and my log, edtFTP log), and then you will see step 6. ==> step 7 ; 7 only doing uploadfile() , and 6 only doing change to [/dw/ftpdata/ftpucc1/upload])

and then, you can check edtftp log and  my log of program , you will see the "uploadfile()"  method do two action, first is change to root folder, and second step is upload file.

so your should check the action of "uploadfile()" method.
by (2.7k points)
I really need to see all of the code that's using our component, to be able to tell what's going on.  When I have this sort of problem within a large application, I often create a small stand-alone test project that isolates the problem that I'm trying to solve, so if I were you I would create a test project that replicates the problem.  It usually only takes a few minutes to do and doing it often makes the problem quite obvious.  If it doesn't reveal the problem then I would be happy to try it out, provided you have a current support agreement.
by (140 points)
My program is not very large, and it is a stand-alone. It is a console for doing one receive or send action. I have another program for checking all tasks those need to send or receive, and then the program will call the console to do one task(This console just using your component). The console have more than one in the same time because we have more files to send different FTP Server.

The problem  is not happen erery times, so I am difficult to get it question by once connection.

The send method is as follow:

other program call
Do_FTP.doSend_FTP();

        /// <summary>
        ///  Do_FTP ???
        /// </summary>
        /// <param name="sServer">FTP???(IP)</param>
        /// <param name="sLoginName">????</param>
        /// <param name="sPort">PORT</param>
        /// <param name="sPwd">??</param>
        public Do_FTP()
        {
            try
            {
                objFtp = new SecureFTPConnection();
                objFtp.LicenseKey = "041-XXXXXXXXX";
                objFtp.LicenseOwner = "MegXXXXXXXXX";
            }
            catch (Exception ex)
            {
                objChgStrFmt.wriMsgToConsole(-1, "Do_FTP?????????:" + ex.Message, "E", "");
                sErrMsg="Do_FTP?????????:" + ex.Message;
            }
        }


  /// <summary>
        /// ????????(??)
        /// </summary>
        /// <returns></returns>
      
  /// <summary>
        /// ????????(??)
        /// </summary>
        /// <returns></returns>
        public int doSend_FTP()
        {
            int iResult = 0; //0:??? -1:??
            bool flag = true;
            MainFTP.sNowMethodName = "doSend_FTP";
            StringBuilder objSBufScrData = new StringBuilder("");
            string sMainFilePath = "";
            string sMainChkFilePath = ""; //H-098-0063

            try
            {

                //????/?????
                this.iReTryNum = int.Parse(MainFTP.vFTP_PARA[25]);  //?????
                this.iCanReTryNum = int.Parse(MainFTP.vFTP_PARA[24]);  //??????


                #region 1.??FTP Server  --> ???????

                if (doConnection() == true)
                {                    #region 2.????????


                    //?????
                    iResult = MainFTP.vFTP_PARA[14].LastIndexOf("\\") + 1;
                    sMainFilePath = MainFTP.vFTP_PARA[14].Substring(0, iResult);


                    if (flag == true)
                    {
                      
                       
                            objFtp.ChangeWorkingDirectory(MainFTP.vFTP_PARA[16]);     
                            objFtp.UploadFile(sMainFilePath + MainFTP.sBufSendName.ToString(), MainFTP.sBufSendName.ToString());                               

                        iResult = 0;  //????????

                    }  //End -if

                    #endregion

                    #region 3.??????
                    if (flag == true)
                    {
                        flag = doCloseConnect();
                    }
                    else
                    {
                        doCloseConnect();
                    }
                    #endregion

                }
                else
                {
                    iResult = -1;  //??????
                }

                #endregion

                if (flag == false)
                {
                    iResult = -1;  //??????
                }

            }
            catch (Exception ex)
            {             
                  iResult = -1;
            }
            finally
            {
                isLoginedOK = 0; //???0
            }
            return iResult;
        }


 /// <summary>
        /// ??FTP????
        /// </summary>
        private bool doConnection()
        {
            bool flag = false;
            try
            {
                if (objFtp.IsConnected == false)
                {
                    init_edtFTPnetPro(MainFTP.sFTP_IP, MainFTP.sFTP_IP, int.Parse(MainFTP.sFTP_PORT));
                    objFtp.UserName = MainFTP.sUSER_NAME;
                    objFtp.Password = MainFTP.sPWD;
                    if (MainFTP.sFTP_TRANSFER_TYPE.Equals("A"))
                        objFtp.TransferType = FTPTransferType.ASCII; //?ascii????,??(???)?binary??
                    objFtp.Connect();
                }
                if (objFtp.IsConnected == true)
                {       
                    objFtp.BeginGetFileInfos(null,null); //???????/??
                    flag = true;
                }
                else {
                    flag = false;
                }
            }
            catch (Exception ex)
            {
                objChgStrFmt.wriMsgToConsole(-1, "Do_FTP.doConnection()????:" + ex.Message, "W", "");
                sErrMsg="Do_FTP.doConnection()????:" + ex.Message;
                flag = false;
            }
            return flag;
        }
=====================
I will change logLevel to ALL for get more information.

  SecureFTPConnection.LogLevel = LogLevel.All;

Thanks!
by (2.7k points)
You're mixing synchronous and asynchronous methods, which is not advisable since you have no control of which sequence operations are carried in.

In doSend_FTP() you call doConnection().  In doConnection() you invoke BeginGetFileInfos and then the method returns.  doSend_FTP() then goes on to call ChangeWorkingDirectory() and then UploadFile().  Since BeginGetFileInfos() instructs SecureFTPConnection to get a file listing on a worker thread, this operation will happen concurrently with ChangeWorkingDirectory() and UploadFile(), which could cause the behaviour that you're seeing.

I don't know why you're calling BeginGetFileInfos() since you don't appear to be using the listing for anything, but if you do need to do it then you should use the synchronous version, i.e. GetFileInfos().
by (140 points)
Maybe BeginGetFileInfos() in doConnection() is a question because I don't understand why the console read root folder sometimes, and that is not an instruct from my program.

I will change the console program for deleting objFtp.BeginGetFileInfos() method in
doConnection() method, and then care it.

Does happen change to root directory due to the same login user connection to FTP Server in different the console processes or different clients?

Thanks!!

Categories

...