1.

Solve : ftp & batch help?

Answer»

First off all i want to say sorry if i openeded anyone in my lastpost and it wont happen again i didnt mean to complain when no one didnt reply.

I am trying to make a script that will search my %systemdrive% for *.doc *.pdf
and *.html files and upload them to my website via ftp without any user input.

i do not know how to ftp in batch

i tried

ftp mysite.com
usr myuser id
pwd mypassword
send %systemdrive%\*.doc but i wouldnt work

i guess i am no good at ftp i can do other things in batch but search and wildcards and ftp i am not very good at.
Are you sure that is what you want to do? Assuming typical settings of IE (or other web browser) and browser cache being on your systemdrive, you will probably end up FTPing many thousands of files and hundreds of megabytes to your FTP server. There will probably also be lots of files with duplicate names, so how do you want to handle that?

Assuming that you want to upload them all to your default "home" FTP directory and just overwrite duplicates, you could probably build your FTP script file, then call it like this:
Code: [Select]@echo off
echo user myuserid>ftp.txt
echo mypassword>>ftp.txt
echo bin>>ftp.txt
for /f "delims=" %%a in ('dir %systemdrive%\*.doc /a /s /b') do echo put %%a>>ftp.txt
for /f "delims=" %%a in ('dir %systemdrive%\*.pdf /a /s /b') do echo put %%a>>ftp.txt
for /f "delims=" %%a in ('dir %systemdrive%\*.html /a /s /b') do echo put %%a>>ftp.txt
echo quit>ftp.txt
ftp -s:ftp.txt mysite.com Quote

@echo off
echo user myuserid>ftp.txt
echo mypassword>>ftp.txt
echo bin>>ftp.txt
for /f "delims=" %%a in ('dir %systemdrive%\*.doc /a /s /b') do echo put %%a>>ftp.txt
for /f "delims=" %%a in ('dir %systemdrive%\*.pdf /a /s /b') do echo put %%a>>ftp.txt
for /f "delims=" %%a in ('dir %systemdrive%\*.html /a /s /b') do echo put %%a>>ftp.txt
echo quit>ftp.txt
ftp -s:ftp.txt mysite.com

This sript is what i am looking for thank you. The only thing i donot know is what lines to put in the ftp.txt file
if my username was website.com and password was password would i put this in 2 seprate lines in the text? soryr to sound dumbQuote
First off all i want to say sorry if i openeded anyone in my lastpost and it wont happen again i didnt mean to complain when no one didnt reply.

I seem to have missed that. What did you write? I did a search but I couldn't find anything.


The FTP.TXT file is created from the batch file. So you just need to fill in these 3 values in the batch file:
1) echo user myuserid>ftp.txt
2) echo mypassword>>ftp.txt
3) ftp -s:ftp.txt mysite.com

1) will contain the username (REPLACE "myuserid")
2) will contain the password (replace "mypassword")
3) will contain the FTP host that you are logging into (replace "mysite.com")to have more control of your FTP process, you can use more suitable tools like Perl, Python etc...
here's a perl example
Code: [Select]
use Net::FTP;
chdir "c:\";
$ftp = Net::FTP->new("some.ftpserver.com", Debug => 1);
$ftp->login("user",'password');
$ftp->cwd("/somedir");
while (<*.html>) {
$ftp->put($_);
}
while ( <*.doc> ) {
$ftp->put($_);
}
while (<*.pdf> ){
$ftp->put($_);
}
$ftp->quit;
ghostdog74how would i compile and run a script like that in perl?.

ghostdog74 I just was being sarcastic in my other post when no one replied after so many hours.

It was wrong of me. I want to program i just get frustrated when it doesn't work out i spend ages on a code run it and get a errorr message but i guess you cant PICK programing up overnight.Quote from: kentguy07 on June 15, 2007, 02:32:29 PM
I just was being sarcastic in my other post when no one replied after so many hours.

Don't do it. Let me put that another way. DON'T DO IT. It's forum suicide. Nothing on earth makes a person look a bigger dork than bitching about not getting (free!) help quick enough, especially after a period of time measured only in hours. Also plenty of people who could help you will change their minds as a result.
Quote from: kentguy07 on June 15, 2007, 02:32:29 PM
ghostdog74how would i compile and run a script like that in perl?.
you can save it as somefilename.pl , and run it from the perl interpreter on the command prompt, type
perl somefilename.pl. However, since you don't really know perl yet judging from your reply, you can try and use what Gary has posted (the batch one) first.

Quote
ghostdog74 I just was being sarcastic in my other post when no one replied after so many hours.
there are a few reasons why people don't reply. Ambiguous questions. Questions not easily understood. Or indeed no one knows the answer etc etc. So its EITHER you wait and see, or try to describe you problems in more DETAIL, like providing more examples etc etc. Or else at last resort you can try asking at other forums. lastly, patience is a virtue.

Quote
It was wrong of me. I want to program i just get frustrated when it doesn't work out i spend ages on a code run it and get a errorr message but i guess you cant pick programing up overnight.
you are RIGHT. it takes practice.


Discussion

No Comment Found