LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (http://www.linuxquestions.org/questions/programming-9/)
-   -   Sending a file to a web server via ftp (http://www.linuxquestions.org/questions/programming-9/sending-a-file-to-a-web-server-via-ftp-340282/)

mrobertson 07-05-2005 12:57 PM

Sending a file to a web server via ftp
 
I have written a vb6 app that generates a simple text file. I want to be able to send that text file to a web server. More specifically, this web server is one of an axis network camera. The camera has a linux os built in and I plan to rean the text file from the camera. The problem is that the camera will not accept files with the .txt extension. So overall, what I need to do is change the name of the file from camdata.txt to just camdata (no extension and then send it to the camera via ftp or another efficient means. The camera does not support sockets so winsock would be out of the question. Could anyone help me with this?

keefaz 07-05-2005 01:09 PM

I think you could use a batch ftp file with the windows ftp built-in command,
so ftp login, upload, close are automatic

try ftp /? or help ftp at the cmd prompt, you look for ftp -f file or similar

mrobertson 07-05-2005 01:11 PM

What would be the syntax to execute these things in vb6? I am not sure I understand.

keefaz 07-05-2005 01:17 PM

I dont know vb6 but that could be :
Code:

system("ftp -s:C:\ftp.cmd");
Where C:\ftp.cmd contains :
Code:

open server
yourusername
yourpassword
cd /path/to/dir/where/upload/the/file
put camdata

Assuming camdata is in the current directory

mrobertson 07-05-2005 01:21 PM

So I just need to type:


Code:

system("ftp -s:C:\ftp.cmd");
on the command line and that would be all?
I dont see how it is going to know what file to get. Could you explain in a little more detail?

keefaz 07-05-2005 01:44 PM

Quote:

I dont see how it is going to know what file to get.
So you want to upload or download the file ?

mrobertson 07-05-2005 01:49 PM

I want to upload the file. If you could let me know exactly what I need to do, that would be great. I really did not understand the last post I have a file that is stored in my c:\ drive and I want to upload it. Thanks.

keefaz 07-05-2005 02:04 PM

so create a file with notepad with the content I posted above
(ftp.cmd) of course replace server with the ftp server address,
and replace yourusername and yourpassword as well
(I think it is simple to understand what to replace, very simple
syntax)

then save it in c:\ftp.cmd
now open cmd.exe and type :
Code:

ftp -s:c:\ftp.cmd

mrobertson 07-06-2005 07:38 AM

I tried to do your suggestion. I made a file that looks as follows:

Code:

ftp://pl7cam3
root
pass
cd c:\Camera Data\camdata.txt
put camdata.txt

When I tried to execute the code, I got the following:

U:\> ftp -s:c:\ftp.cmd
ftp> ftp://pl7cam3
Invalid Command
ftp>root
Invalid Command
ftp>pass
Invalid Command
ftp> cd c:\Camera Data\camdata.txt
Not Connected
ftp> put camdata.txt
Not Connected


There are a couple of questions that I have however. My camdata.txt is stored locally on my pc. This program will have to run on a separate pc eventually meaning that it will have to go on the network and get the file from my pc. So my cd c:\......... may not be right. Also should the ftp.cmd be saved to the c:\ drive on my pc or to the camera that it will run on(a separate pc).....therefore I would be executing these commands from a telnet session. That may be confusing but I guess the first thing would be to atleast get the code working.......I was not able to connect to a ftp session. If from the u:/> prompt I typed ftp pl7cam3...I was able to get connected to a session.

mrobertson 07-06-2005 08:51 AM

I have made some progress. I changed my code to the following and got a connection and successful commands:

Code:

open pl7cam3
root
pass
cd etc
put camdata.txt

Now I am getting a file not found message. camdata.text is located locally in the c:\Camera Data\camdata.text location. How would I be able to get it from there and put it in the etc directory of pl7cam3?

mrobertson 07-06-2005 09:04 AM

Ok...I have been able to get the file to be transfered by using:

Code:

open pl7cam3
root
pass
cd etc
get camdata.txt camdata
put camdata

No I have one last question. The file is now on the camera.....I have a script on the camera that will read the file which is:

Code:

#!/bin/sh
while sleep1
        do
                cat camdata
done

I need to add code to make sure that file is ftp 'd to the camera every second and then read and printed out. Do I have to save the ftp.cmd to the camera and thenuse the following code:

Code:

#!/bin/sh
while sleep1
        do
                ftp -s://pl7cam3/etc/ftp.cmd
                cat camdata
done

Or what would be the way to do this?

mrobertson 07-06-2005 09:12 AM

Or is there a way that I can execute :


ftp -s:c:\ftp.cmd

from vb6 every second based on a timer?


All times are GMT -5. The time now is 11:33 PM.