Using variables in ftp connection by cmd

后端 未结 3 1593
逝去的感伤
逝去的感伤 2021-01-07 00:55

How I can use variables in ftp? This is what have i done: file a.bat:

set file=test ftp -s:b.txt IP

file b.txt

user password get %

3条回答
  •  耶瑟儿~
    2021-01-07 01:43

    The reason the %-artifact didn't work in the BAT file was that that token was never seen and replaced. Just as in a UNIX shell script, $-substitutions are performed when those lines are collected and tokenized. Since the line containing the %file% was input to FTP, it was collected and parsed by FTP, not by the "DOS" shell.

    In UNIX, you can solve this problem by piping the directives through FTP. That is to say, while this (where $1 is a filename parameter supplied on the command line):

    ftp << FTP_CMDS  
    user joe  
    pass joesPassword  
    get $1  
    quit  
    FTP_CMDS
    

    wouldn't work, THIS:

    (echo user joe;  
     echo pass joesPassword;  
     echo get $1;  
     echo quit ) | ftp
    

    WOULD work.

提交回复
热议问题