假设我想将文件从Windows本地目录(不在服务器上)复制到AS / 400 IFS,如何使用cmd实现此目的?我知道还有其他方法,如硬盘映射或iSeries Navigator,但这里的目的是使用VBA执行此类命令,以便当有人单击按钮时,目标文件将在IFS中重复。我尝试直接在cmd中使用copy命令,但由于未提供用户配置文件和密码,因此失败。那么有可能在cmd中使用命令实现这一点吗?怎么样?如果在此过程中弹出一个窗口要求我填写用户名和密码,这是可以接受的。
答案 0 :(得分:3)
您对VBA的选择是:
您可以创建一个ftp脚本文件并执行它。以下是我通常使用批处理文件的方法:
@echo off
echo open AS400_HOSTNAME > ftp.cmd
echo user AS400_USERNAME AS400_PASSWORD >> ftp.cmd
echo ascii >> ftp.cmd
echo cd AS400_PATH >> ftp.cmd
echo put PC_FILENAME AS400_FILENAME >> ftp.cmd
echo quit >> ftp.cmd
ftp.exe -n -s:ftp.cmd
将驱动器映射到iSeries Netserver时,您可以强制使用用户名和密码:
NET USE Z: \\as400\share /USER:username password
COPY FILE.TXT Z:\DIR
NET USE Z: /DELETE
答案 1 :(得分:0)
Imports System
Imports System.Data
Imports System.IO
Imports System.Diagnostics
Imports Microsoft.VisualBasic.FileIO
Module Module1
Dim strCmdArg As String = "/c NET USE P: \\host.domain.com\root\home\user /user:host.domain.com\user password"
Dim strCmdDel As String = "/c NET USE /DELETE P:"
Dim strLocalFile As String = "\\windowsserver\share\folder\"
Dim strRemoteFile As String = "P:\"
Dim boolOverwrite As Boolean = True
Dim job As Process = Process.Start("cmd.exe", strCmdArg)
Dim endjob As Process = Process.Start("cmd.exe", strCmdDel)
Sub Main()
Try
job.Start()
job.Dispose()
job.Close()
FileSystem.CopyDirectory(strLocalFile, strRemoteFile, boolOverwrite)
endjob.Start()
endjob.Dispose()
endjob.Close()
Catch Ex As Exception
Console.WriteLine(Ex.Message)
Console.WriteLine(Ex.StackTrace.ToString)
endjob.Start()
endjob.Dispose()
endjob.Close()
End Try
End Sub
End Module