有没有办法在 SAS Enterprise Guide 中将 SFTP 文件从 Linux 目录传送到 Windows?

Is there a way to SFTP files from Linux directory to Windows within SAS Enterprise Guide?

我正在尝试使用 SAS 将文件从 Linux 通过 SFTP 传输到 Windows 目录,但我一直 运行 出错。

我的代码是:

filename attn '/<Linux Directory>/file.doc';

filename outfile sftp '/<Linux Directory>/file.doc'; cd ='C:\Temp\file.doc'
options="oIdentityFile='~/.ssh/authorized_keys' -oPort=<port number>" 
host="<hostname>" user="<username>"  DEBUG  ;


data _null_;
infile attn ;
file outfile  ;
input;
put _infile_;
run;

但我一直面临以下错误:

ERROR: Physical file does not exist, /<Linux directory>/file.doc.

NOTE: usage: sftp [-1Cv] [-B buffer_size] [-b batchfile] [-F ssh_config]            [-o ssh_option] [-P sftp_server_path] [-R 
      num_requests]            [-S program] [-s subsystem | sftp_server] host       sftp [user@]host[:file ...]       sftp 
      [user@]host[:dir[/]]       sftp -b batchfile [user@]host

NOTE: cd C:\Temp\task1045v2_13yrs_cc.doc

ERROR: Directory or file C:/temp/file.doc/ doesn't exist.

NOTE: The SAS System stopped processing this step because of errors.

基本上我正在尝试在 SAS 中重新创建以下 Visual Basic 代码:

open sftp://<userid>:<password>@<hostname> -hostkey="ssh-rsa <Port Number> <key>"
option echo on
option batch on
option confirm off
option transfer ascii
lcd "<Windows path/>" 
cd <Linux path>
get <file.doc> /*the file which need to get transferred from linux to windows*/
close
exit

VB Code (actual code to transfer):

    strPath = "C:\Temp\"
    strFileName = "<filename>.txt"
    strFullName = objFSO.BuildPath(strPath, strFileName)
    strLogName = objFSO.BuildPath(strPath, "<logfilename>.log") 

Set objShell = CreateObject("WScript.Shell")
objShell.CurrentDirectory = strPath

Set objExec = objShell.Exec("""C:\Program Files (x86)\WinSCP\WinSCP.exe"" /console /script=""" & strFullName & """ /log=""" & strLogName & """")

    Set objExec = Nothing
    Set objShell = Nothing

如有任何建议,我们将不胜感激。谢谢!

您似乎在尝试移动名为 file.doc 的文件而不更改其名称。确保告诉 SFTP 您要写入文件的目标机器上的正确位置。

%let source=/<Linux Directory>;
%let target=C:\Temp;
%let fname=file.doc;

filename attn "&source/&fname";

filename outfile sftp "&fname" cd ="&target\"
  options="oIdentityFile='~/.ssh/authorized_keys' -oPort=<port number>" 
  host="<hostname>" user="<username>"  DEBUG  
;

注意: 当语句太长以至于您想将其分成多行以提高可读性时,我发现最好将语句结尾的分号放在新队。就像您将 end; 语句放在一个新行中以表示多个语句块一样。这将使您更容易发现代码中丢失的(或在您的情况下,额外的)分号。