teratail header banner
teratail header banner
質問するログイン新規登録

質問編集履歴

1

コードの追加

2021/11/26 00:36

投稿

August.
August.

スコア7

title CHANGED
File without changes
body CHANGED
@@ -101,4 +101,64 @@
101
101
  }
102
102
  }
103
103
 
104
+ ```
105
+
106
+ 重要なコードが抜けていました、申し訳ないです
107
+
108
+ ```kotlin
109
+ package com.example.carno
110
+
111
+ import android.util.Log
112
+ import java.io.File
113
+ import java.io.IOException
114
+ import java.util.*
115
+ import it.sauronsoftware.ftp4j.FTPClient
116
+ import it.sauronsoftware.ftp4j.FTPException
117
+ import kotlinx.coroutines.*
118
+
119
+ class FTPTransfer {
120
+ var filename = ""
121
+
122
+ fun SetFileName( TEST:String ){
123
+ filename = TEST
124
+
125
+ }
126
+
127
+ // private suspend fun FtpAsyncTask( filename : String ){
128
+ fun FtpAsyncTask( filename : String ){
129
+ // fun FtpAsyncTask(){
130
+ // onPreExecuteと同等の処理
131
+ // withContext(Dispatchers.Main) {
132
+ //// Log.d( localClassName, "始めます")
133
+ // }
134
+ var myFTPClient = FTPClient()
135
+ try {
136
+ // myFTPClient.connect("192.168.11.240", 21)
137
+ // myFTPClient.login("FC-USER", "subaru")
138
+ myFTPClient.connect("192.168.76.98", 21 )
139
+ myFTPClient.login("ftptest", "unitec2244")
140
+ myFTPClient.type = FTPClient.TYPE_BINARY
141
+ myFTPClient.isPassive = true
142
+ myFTPClient.changeDirectory("./")
143
+
144
+ var filename2 = filename
145
+ val uploadfile = File(filename2)
146
+ myFTPClient.upload(uploadfile)
147
+ myFTPClient.logout()
148
+ myFTPClient.disconnect(true)
149
+ } catch (e: Exception) {
150
+ println(e.message)
151
+ } catch (e: FTPException) {
152
+ println(e.message)
153
+ } finally {
154
+ if (myFTPClient.isConnected()) {
155
+ try {
156
+ myFTPClient.disconnect(true)
157
+ } catch (e: IOException) {
158
+ }
159
+ }
160
+ // myFTPClient = null
161
+ }
162
+ }
163
+ }
104
164
  ```