vba 如何使用 cmd 将文件从 Windows 复制到 AS/400 IFS?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/10635575/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-11 16:10:48  来源:igfitidea点击:

How to copy a file from Windows to AS/400 IFS using cmd?

vbacopycmdibm-midrange

提问by God_of_Thunder

Suppose I want to copy a file from a Windows local directory (not on a server) to the AS/400 IFS, how to achieve this using cmd? I know there are other ways like hard drive mapping or iSeries Navigator but the aim here is to use VBA to execute such command so that when someone click a button the target file will be duplicated in the IFS. I tried to use copy command in cmd directly but it failed because the user profile and password were not supplied. So is it possible to achieve this using command in cmd? How? It is acceptable if during the process a window pops up to ask me to fill in user name and password.

假设我想将一个文件从 Windows 本地目录(不在服务器上)复制到 AS/400 IFS,如何使用 cmd 来实现?我知道还有其他方法,如硬盘映射或 iSeries Navigator,但这里的目的是使用 VBA 执行此类命令,以便当有人单击按钮时,目标文件将在 IFS 中复制。我尝试直接在 cmd 中使用 copy 命令,但由于未提供用户配置文件和密码而失败。那么是否可以在 cmd 中使用命令来实现这一点?如何?如果在此过程中弹出窗口要求我填写用户名和密码,则可以接受。

回答by James Allman

Your options with VBA are:

您对 VBA 的选择是:

  • Upload to the IFS via FTP.
  • Upload to the IFS via SMB (iSeries Netserver).
  • Upload to the database and copy to the IFS using [Client] Access automation.
  • 通过 FTP 上传到 IFS。
  • 通过 SMB ( iSeries Netserver)上传到 IFS 。
  • 使用 [Client] Access 自动化上传到数据库并复制到 IFS。


FTP Example

FTP 示例

You can create an ftp script file and execute it. Here's how I usually do it with a batch file:

您可以创建一个 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

NetServer Example

网络服务器示例

You can force a username and password when mapping a drive to the iSeries Netserver:

将驱动器映射到 iSeries Netserver 时,您可以强制使用用户名和密码:

NET USE Z: \as400\share /USER:username password
COPY FILE.TXT Z:\DIR
NET USE Z: /DELETE

回答by Joshua Perry

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