QA@IT

windows embedded compact 7  で FTP

3032 PV

Canon Prea GT-31 で wininet.dll で FTP通信を行おうとしています。
下記手順で処理を行うと 4)で エラー87となってしまいます。
1)->2)->4)でも同じエラーになります。
GT-31 OS は Windows embedded Compact 7です.
何方かお知恵をお貸し下さい。

 1) InternetOpen
2) InternetConnect
3) FtpGetFile or FtpPutFile
4) InternetCloseHandle (2)に対して)

--- 以下しVB.NETのソースコードです ---

Sample vb.net

Imports System.Runtime.InteropServices

Public Class Form1

Private lngWinNet As Integer = 0
Private lngFtpHnd As Integer = 0

'---------------------------------------------------
'InternetOpen
Private Declare Function InternetOpen _
             Lib "wininet.dll" _
          (ByVal lpszAgent As String _
         , ByVal dwAccessType As Integer _
         , ByVal lpszProxyName As String _
         , ByVal lpszProxyBypass As String _
         , ByVal dwFlags As Integer) As Integer

'dwAccessType(接続方法)
'全てのホスト名をローカルで解決します
Private Const INTERNET_OPEN_TYPE_DIRECT As Integer = &H1
'既存の設定(要はIEの設定)を利用します
Private Const INTERNET_OPEN_TYPE_PRECONFIG As Integer = &H0
'プロキシサーバ経由で接続します
Private Const INTERNET_OPEN_TYPE_PROXY As Integer = &H3

'dwFlags(ネットワーク使用有無)
'サーバーから取得します
Private Const INTERNET_FLAG_ASYNC As Integer = &H10000000
'キャッシュから取り出します(ネットワークを使用しません)
Private Const INTERNET_FLAG_FROM_CACHE As Integer = &H1000000

'--------------------------------------------------------
'InternetConnect
Private Declare Function InternetConnect _
             Lib "wininet.dll" _
          (ByVal hInternet As Integer _
         , ByVal lpszServerName As String _
         , ByVal nServerPort As Integer _
         , ByVal lpszUsername As String _
         , ByVal lpszPassword As String _
         , ByVal dwService As Integer _
         , ByVal dwFlags As Integer _
         , ByVal dwContext As Integer) As Integer

'nServerPort(接続ポート)
'FTP
Private Const INTERNET_DEFAULT_FTP_PORT As Integer = 21
'GOPHER
Private Const INTERNET_DEFAULT_GOPHER_PORT As Integer = 70
'HTTP
Private Const INTERNET_DEFAULT_HTTP_PORT As Integer = 80
'HTTPS
Private Const INTERNET_DEFAULT_HTTPS_PORT As Integer = 443
'SOCK
Private Const INTERNET_DEFAULT_SOCKS_PORT As Integer = 1080

''dwService(サービスの種類)
''FTP
'Private Const INTERNET_SERVICE_FTP As Long = 1
''GOPHER
'Private Const INTERNET_SERVICE_GOPHER As Long = 2
''HTTP
'Private Const INTERNET_SERVICE_HTTP As Long = 3

'dwService(サービスの種類)
'FTP
Private Const INTERNET_SERVICE_FTP As Integer = 1
'GOPHER
Private Const INTERNET_SERVICE_GOPHER As Integer = 2
'HTTP
Private Const INTERNET_SERVICE_HTTP As Integer = 3

'dwFlags(オプション)
'PASSIVEモードで接続(FTP時)
Private Const INTERNET_FLAG_PASSIVE = &H8000000


'---------------------------------------------------------
'FTPでダウンロード
Private Declare Function FtpGetFile _
             Lib "wininet.dll" _
          (ByVal hConnect As Integer _
         , ByVal lpszRemoteFile As String _
         , ByVal lpszNewFile As String _
         , ByVal fFailIfExists As Boolean _
         , ByVal dwFlagsAndAttributes As Integer _
         , ByVal dwFlags As Integer _
         , ByVal dwContext As Long) As Boolean

'dwFlagsAndAttributes(ダウンロード後のファイルの属性)
'読み込み専用
Private Const FILE_ATTRIBUTE_READONLY As Integer = &H1
'隠しファイル
Private Const FILE_ATTRIBUTE_HIDDEN As Integer = &H2
'システムファイル
Private Const FILE_ATTRIBUTE_SYSTEM As Integer = &H4
'ディレクトリ(フォルダ)
Private Const FILE_ATTRIBUTE_DIRECTORY As Integer = &H10
'アーカイブファイル
Private Const FILE_ATTRIBUTE_ARCHIVE As Integer = &H20
'通常のファイル
Private Const FILE_ATTRIBUTE_NORMAL As Integer = &H80

'dwFlags(転送方法)
'アスキーモード
Private Const FTP_TRANSFER_TYPE_ASCII As Integer = &H1
'バイナリモード
Private Const FTP_TRANSFER_TYPE_BINARY As Integer = &H2

'dwFlags(ダウンロード方法)
'キャッシュを無視し、サーバから強制的にダウンロード
Private Const INTERNET_FLAG_RELOAD As Integer = &H80000000
'ダウンロードファイルをキャッシュに加えない
Private Const INTERNET_FLAG_DONT_CACHE As Integer = &H4000000
'サーバから再読み込みします
Private Const INTERNET_FLAG_RESYNCHRONIZE As Integer = &H800
'キャッシュできないときに一時ファイルを生成
Private Const INTERNET_FLAG_NEED_FILE As Integer = &H10
'有効期限、最終更新時刻がサーバから返されない場合は強制的に再読み込み
Private Const INTERNET_FLAG_HYPERLINK As Integer = &H400


'-------------------------------------------------------------------
'FTPでアップロード
Private Declare Function FtpPutFile _
             Lib "wininet.dll" _
          (ByVal hConnect As Integer _
         , ByVal lpszLocalFile As String _
         , ByVal lpszNewRemoteFile As String _
         , ByVal dwFlags As Integer _
         , ByVal dwContext As Long) As Boolean


'------------------------------------------------------------------
'
Private Declare Function InternetCloseHandle _
         Lib "wininet.dll" _
      (ByVal hInternet As Integer) As Integer






'------------------------
'   InternetOpen
'------------------------
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click


    Try
        lngWinNet = InternetOpen(vbNullString _
                               , INTERNET_OPEN_TYPE_PRECONFIG _
                               , vbNullString _
                               , vbNullString _
                               , 0)
        MessageBox.Show(Err.LastDllError.ToString, "InternetOpen")
        TextBox8.Text = lngWinNet.ToString("X")
    Catch ex As Exception
        MessageBox.Show(ex.Message, "InternetOpen ex")
    End Try

End Sub

'-----------------------
'   InternetConnect
'----------------------
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click

    Dim strServerName As String = TextBox1.Text
    Dim strUserName As String = TextBox2.Text
    Dim strPassWord As String = TextBox3.Text

    lngFtpHnd = InternetConnect(lngWinNet _
               , strServerName _
               , INTERNET_DEFAULT_FTP_PORT _
               , strUserName _
               , strPassWord _
               , INTERNET_SERVICE_FTP _
               , INTERNET_FLAG_PASSIVE _
               , 0)
    MessageBox.Show(Err.LastDllError.ToString, "InternetConnect")
    TextBox9.Text = lngFtpHnd.ToString("X")
End Sub

'-----------------------
'   FtpPutFile
'-----------------------
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click

    Dim strFromFilePath As String = TextBox5.Text
    Dim strToFilePath As String = TextBox4.Text
    Dim blnRet As Boolean
    MessageBox.Show(strFromFilePath & "->" & strToFilePath, "FtpPutFile")

    blnRet = FtpPutFile(lngFtpHnd _
            , strFromFilePath _
            , strToFilePath _
            , FTP_TRANSFER_TYPE_ASCII _
            , 0)

    MessageBox.Show(Err.LastDllError.ToString, "FtpPutFile")


End Sub

'-----------------------
'   FtpGetFile
'-----------------------
Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click

    Dim strFromFilePath As String = TextBox6.Text
    Dim strToFilePath As String = TextBox7.Text

    MessageBox.Show(strFromFilePath & "->" & strToFilePath, "FtpGetFile")
    FtpGetFile(lngFtpHnd _
            , strFromFilePath _
            , strToFilePath _
            , False _
            , FILE_ATTRIBUTE_NORMAL _
            , FTP_TRANSFER_TYPE_ASCII _
            , 0)

    MessageBox.Show(Err.LastDllError.ToString, "FtpGetFile")

End Sub

'------------------------
'   InternetClose
'------------------------
Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click

    MessageBox.Show("lngWinNet=" & lngWinNet.ToString("X"), "InternetClose")
    If lngWinNet <> 0 Then
        InternetCloseHandle(lngWinNet)
        MessageBox.Show(Err.LastDllError.ToString, "InternetClose")
    Else
        MessageBox.Show("オープンされていません。", "InternetClose")
    End If

End Sub

'--------------------------
'   FTP Close
'--------------------------
Private Sub Button6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button6.Click

    MessageBox.Show("lngFtpHndt=" & lngFtpHnd.ToString("X"), "DisConnect")
    If lngFtpHnd <> 0 Then
        InternetCloseHandle(lngFtpHnd)
        MessageBox.Show(Err.LastDllError.ToString, "DisConnect")
    Else
        MessageBox.Show("オープンされていません。", "DisConnect")
    End If

End Sub

'--------------------------
'
'--------------------------
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

    ''MessageBox.Show("Integer=" & Marshal.SizeOf(GetType(Integer)))
    ''MessageBox.Show("Long=" & Marshal.SizeOf(GetType(Long)))
    TextBox1.Text = "192.168.199.22"
    TextBox2.Text = "anonymous"
    TextBox3.Text = ""

    TextBox4.Text = "/KENSIN/KENSNF.DAT"
    TextBox5.Text = "\SLOT2\URIA.D"

    TextBox6.Text = "/KENSIN/KENSNF.SEQ"
    TextBox7.Text = "\SLOT2\MAST.D"
End Sub

End Class

ウォッチ

この質問への回答やコメントをメールでお知らせします。