Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. FtpPutFile problem

FtpPutFile problem

Scheduled Pinned Locked Moved C / C++ / MFC
comsysadminhelpquestion
8 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    dellthinker
    wrote on last edited by
    #1

    Hi all. I've tried to use this but it doesnt seem to work. One time i tried it and it worked very well. The second time i tried it it didnt work. What it does is it connects well and sends the file. But problem is that there is nothing in the text file. Here is what i have so far. #include #include #include using namespace std; void FileSubmit() { char *user="user"; char *pass="password"; char *ftpserver="ftp.server.com"; HINTERNET hInternet; HINTERNET hFtpSession; hInternet = InternetOpen(NULL,INTERNET_OPEN_TYPE_DIRECT,NULL,NULL,0); hFtpSession = InternetConnect(hInternet,ftpserver , INTERNET_DEFAULT_FTP_PORT, user, pass, INTERNET_SERVICE_FTP, 0, 0); if(FtpPutFile(hFtpSession, "C:\\test.txt", "file.txt", FTP_TRANSFER_TYPE_ASCII, 0) == TRUE){ cout << "File Sent! " << endl; Sleep(1000); InternetCloseHandle(hFtpSession); InternetCloseHandle(hInternet); } else{ cout << "File didnt send " << endl; } } int main(){ FileSubmit(); return 0; } I know text files need to be sent in ASCII mode so i switched to that and it still didnt work. It uploads the file but the file is empty. Whats going on??? Thanx in advance!

    P D 2 Replies Last reply
    0
    • D dellthinker

      Hi all. I've tried to use this but it doesnt seem to work. One time i tried it and it worked very well. The second time i tried it it didnt work. What it does is it connects well and sends the file. But problem is that there is nothing in the text file. Here is what i have so far. #include #include #include using namespace std; void FileSubmit() { char *user="user"; char *pass="password"; char *ftpserver="ftp.server.com"; HINTERNET hInternet; HINTERNET hFtpSession; hInternet = InternetOpen(NULL,INTERNET_OPEN_TYPE_DIRECT,NULL,NULL,0); hFtpSession = InternetConnect(hInternet,ftpserver , INTERNET_DEFAULT_FTP_PORT, user, pass, INTERNET_SERVICE_FTP, 0, 0); if(FtpPutFile(hFtpSession, "C:\\test.txt", "file.txt", FTP_TRANSFER_TYPE_ASCII, 0) == TRUE){ cout << "File Sent! " << endl; Sleep(1000); InternetCloseHandle(hFtpSession); InternetCloseHandle(hInternet); } else{ cout << "File didnt send " << endl; } } int main(){ FileSubmit(); return 0; } I know text files need to be sent in ASCII mode so i switched to that and it still didnt work. It uploads the file but the file is empty. Whats going on??? Thanx in advance!

      P Offline
      P Offline
      Peter Weyzen
      wrote on last edited by
      #2

      Try opening the connection in passive mode..... I had the same problem.... worked for me.

      ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Peter Weyzen Staff Engineer [SoonR Inc -- PC Power delivered to your phone](http://www.soonr.com)

      1 Reply Last reply
      0
      • D dellthinker

        Hi all. I've tried to use this but it doesnt seem to work. One time i tried it and it worked very well. The second time i tried it it didnt work. What it does is it connects well and sends the file. But problem is that there is nothing in the text file. Here is what i have so far. #include #include #include using namespace std; void FileSubmit() { char *user="user"; char *pass="password"; char *ftpserver="ftp.server.com"; HINTERNET hInternet; HINTERNET hFtpSession; hInternet = InternetOpen(NULL,INTERNET_OPEN_TYPE_DIRECT,NULL,NULL,0); hFtpSession = InternetConnect(hInternet,ftpserver , INTERNET_DEFAULT_FTP_PORT, user, pass, INTERNET_SERVICE_FTP, 0, 0); if(FtpPutFile(hFtpSession, "C:\\test.txt", "file.txt", FTP_TRANSFER_TYPE_ASCII, 0) == TRUE){ cout << "File Sent! " << endl; Sleep(1000); InternetCloseHandle(hFtpSession); InternetCloseHandle(hInternet); } else{ cout << "File didnt send " << endl; } } int main(){ FileSubmit(); return 0; } I know text files need to be sent in ASCII mode so i switched to that and it still didnt work. It uploads the file but the file is empty. Whats going on??? Thanx in advance!

        D Offline
        D Offline
        David Crow
        wrote on last edited by
        #3

        dellthinker wrote:

        But problem is that there is nothing in the text file.

        So is the source file empty?


        "Normal is getting dressed in clothes that you buy for work and driving through traffic in a car that you are still paying for, in order to get to the job you need to pay for the clothes and the car and the house you leave vacant all day so you can afford to live in it." - Ellen Goodman

        "To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne

        D 1 Reply Last reply
        0
        • D David Crow

          dellthinker wrote:

          But problem is that there is nothing in the text file.

          So is the source file empty?


          "Normal is getting dressed in clothes that you buy for work and driving through traffic in a car that you are still paying for, in order to get to the job you need to pay for the clothes and the car and the house you leave vacant all day so you can afford to live in it." - Ellen Goodman

          "To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne

          D Offline
          D Offline
          dellthinker
          wrote on last edited by
          #4

          DavidCrow wrote:

          So is the source file empty?

          Yes, as in 0 bytes. And how do i open it in passive mode? I didnt see an option for it.

          V D 2 Replies Last reply
          0
          • D dellthinker

            DavidCrow wrote:

            So is the source file empty?

            Yes, as in 0 bytes. And how do i open it in passive mode? I didnt see an option for it.

            V Offline
            V Offline
            vijay_aroli
            wrote on last edited by
            #5

            dellthinker wrote:

            And how do i open it in passive mode?

            Use INTERNET_FLAG_PASSIVE flag for dwFlags parameter.

            Regards, Vijay. God may not give us what we 'want', but he surely gives us what we 'need'.

            D 1 Reply Last reply
            0
            • V vijay_aroli

              dellthinker wrote:

              And how do i open it in passive mode?

              Use INTERNET_FLAG_PASSIVE flag for dwFlags parameter.

              Regards, Vijay. God may not give us what we 'want', but he surely gives us what we 'need'.

              D Offline
              D Offline
              dellthinker
              wrote on last edited by
              #6

              Well that seemed to do the trick. However i ran Wireshark and it doesnt exactly request PASV before sending. *shrugs* We dont explain why it works that way. It just works! Thanx for your replies, i've been at it for ages and now i can finally move on to the next option task :)

              1 Reply Last reply
              0
              • D dellthinker

                DavidCrow wrote:

                So is the source file empty?

                Yes, as in 0 bytes. And how do i open it in passive mode? I didnt see an option for it.

                D Offline
                D Offline
                David Crow
                wrote on last edited by
                #7

                dellthinker wrote:

                Yes, as in 0 bytes.

                So if the source file is 0 bytes and the destination file is 0 bytes, what's the problem?


                "Normal is getting dressed in clothes that you buy for work and driving through traffic in a car that you are still paying for, in order to get to the job you need to pay for the clothes and the car and the house you leave vacant all day so you can afford to live in it." - Ellen Goodman

                "To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne

                D 1 Reply Last reply
                0
                • D David Crow

                  dellthinker wrote:

                  Yes, as in 0 bytes.

                  So if the source file is 0 bytes and the destination file is 0 bytes, what's the problem?


                  "Normal is getting dressed in clothes that you buy for work and driving through traffic in a car that you are still paying for, in order to get to the job you need to pay for the clothes and the car and the house you leave vacant all day so you can afford to live in it." - Ellen Goodman

                  "To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne

                  D Offline
                  D Offline
                  dellthinker
                  wrote on last edited by
                  #8

                  Sorry i read that wrong. The file on my machine was 1kb. And before i added the INTERNET_FLAG_PASSIVE argument it would upload the file, but on the ftp server it would be 0KB when the original file was 1kb

                  1 Reply Last reply
                  0
                  Reply
                  • Reply as topic
                  Log in to reply
                  • Oldest to Newest
                  • Newest to Oldest
                  • Most Votes


                  • Login

                  • Don't have an account? Register

                  • Login or register to search.
                  • First post
                    Last post
                  0
                  • Categories
                  • Recent
                  • Tags
                  • Popular
                  • World
                  • Users
                  • Groups