Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
H
HIMSScannerService
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
HIMSScanner
HIMSScannerService
Commits
dbf15746
Commit
dbf15746
authored
Dec 12, 2024
by
Krishna Reddy Tamatam
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added Delete documnet function
parent
e8b037e4
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
54 additions
and
17 deletions
+54
-17
FTPManagementAPIController.cs
Controllers/FTPManagementAPIController.cs
+54
-17
No files found.
Controllers/FTPManagementAPIController.cs
View file @
dbf15746
...
...
@@ -159,7 +159,7 @@ namespace FTP_Services.Services.Controllers
string
DatabaseName
=
_appSettings
.
ConnectionString
;
_appSettings
.
ConnectionString
=
_appSettings
.
AdminConnectionString
;
FTPDataAdapter
adapter
=
new
FTPDataAdapter
(
_appSettings
);
List
<
ConfigValues
>?
RequestsList
=
adapter
.
ConfigValues
(
CompanyId
,
DatabaseName
);
List
<
ConfigValues
>?
RequestsList
=
adapter
.
ConfigValues
(
CompanyId
,
DatabaseName
);
return
Ok
(
RequestsList
);
}
catch
(
Exception
ex
)
...
...
@@ -272,7 +272,7 @@ namespace FTP_Services.Services.Controllers
}
[
HttpPost
(
"DownloadBase64DataAsync"
)]
public
async
Task
<
string
>
DownloadBase64DataAsync
(
string
fileNameWithPath
,
bool
IsExternal
)
public
async
Task
<
string
>
DownloadBase64DataAsync
(
string
fileNameWithPath
,
bool
IsExternal
)
{
bool
isFTPMODE
=
_appSettings
.
FTPConfiguration
.
FTPMODE
;
var
base64
=
string
.
Empty
;
...
...
@@ -348,11 +348,11 @@ namespace FTP_Services.Services.Controllers
try
{
var
fileStream
=
new
FileStream
(
strFullPath
,
FileMode
.
Open
,
FileAccess
.
Read
,
FileShare
.
Read
);
var
fileStream
=
new
FileStream
(
strFullPath
,
FileMode
.
Open
,
FileAccess
.
Read
,
FileShare
.
Read
);
var
base64Stream
=
new
Base64EncodingStream
(
fileStream
);
return
new
FileStreamResult
(
base64Stream
,
"application/octet-stream"
)
{
FileDownloadName
=
Path
.
GetFileName
(
fileNameWithPath
)
FileDownloadName
=
Path
.
GetFileName
(
fileNameWithPath
)
};
}
catch
(
Exception
ex
)
...
...
@@ -446,7 +446,7 @@ namespace FTP_Services.Services.Controllers
||
response
.
StatusCode
==
FtpStatusCode
.
FileActionOK
;
return
success
;
}
//Using for Scan upload
...
...
@@ -1122,16 +1122,38 @@ namespace FTP_Services.Services.Controllers
}
[
HttpPost
(
"DeleteFTPFile"
)]
public
async
Task
<
int
>
DeleteFTPFile
(
string
fileNameWithDestinationPath
)
public
async
Task
<
string
>
DeleteFTPFile
(
string
fileNameWithDestinationPath
)
{
bool
isFTPMODE
=
_appSettings
.
FTPConfiguration
.
FTPMODE
;
string
result
=
string
.
Empty
;
if
(
isFTPMODE
==
true
)
{
result
=
await
DeleteFileFTPAsync
(
fileNameWithDestinationPath
);
}
else
{
result
=
await
DeleteFileLocallyAsync
(
fileNameWithDestinationPath
);
}
return
result
;
}
private
async
Task
<
string
>
DeleteFileFTPAsync
(
string
sourceFilePath
)
{
try
{
string
FTPURL
=
_appSettings
.
FTPConfiguration
.
FtpURL
.
ToString
();
string
FTPUserName
=
_appSettings
.
FTPConfiguration
.
Username
.
ToString
();
string
FTPPassword
=
_appSettings
.
FTPConfiguration
.
Password
.
ToString
();
string
strSourceFullPath
=
""
;
string
strBasePath
=
_appSettings
.
FTPConfiguration
.
DestinationPathFtp
.
ToString
()
.
Trim
();
sourceFilePath
=
sourceFilePath
.
Replace
(
"/"
,
"\\"
).
TrimStart
(
'\\'
);
strSourceFullPath
=
Path
.
Combine
(
strBasePath
,
sourceFilePath
);
FtpWebRequest
ftp
=
(
FtpWebRequest
)
WebRequest
.
Create
(
FTPURL
+
fileNameWithDestination
Path
);
WebRequest
.
Create
(
FTPURL
+
strSourceFull
Path
);
ftp
.
Credentials
=
new
NetworkCredential
(
FTPUserName
,
FTPPassword
);
ftp
.
KeepAlive
=
true
;
ftp
.
UseBinary
=
true
;
...
...
@@ -1140,21 +1162,36 @@ namespace FTP_Services.Services.Controllers
FtpWebResponse
response
=
(
FtpWebResponse
)
await
ftp
.
GetResponseAsync
();
var
statuscode
=
(
int
)
response
.
StatusCode
;
response
.
Close
();
return
statuscode
;
return
""
;
}
catch
(
WebException
ex
)
{
FtpWebResponse
response
=
(
FtpWebResponse
)
ex
.
Response
;
if
(
response
.
StatusCode
==
FtpStatusCode
.
ActionNotTakenFileUnavailable
)
{
response
.
Close
();
return
1
;
}
else
return
"Error deleting file: "
+
ex
.
Message
.
ToString
();
}
}
private
async
Task
<
string
>
DeleteFileLocallyAsync
(
string
sourceFilePath
)
{
string
strSourceFullPath
=
""
;
try
{
string
strBasePath
=
_appSettings
.
FTPConfiguration
.
DestinationPathFile
.
ToString
()
.
Trim
();
sourceFilePath
=
sourceFilePath
.
Replace
(
"/"
,
"\\"
).
TrimStart
(
'\\'
);
strSourceFullPath
=
Path
.
Combine
(
strBasePath
,
sourceFilePath
);
if
(!
System
.
IO
.
File
.
Exists
(
strSourceFullPath
))
{
response
.
Close
();
return
0
;
return
"Source file does not exist."
;
}
System
.
IO
.
File
.
Delete
(
strSourceFullPath
);
return
""
;
}
catch
(
Exception
ex
)
{
return
"Error deleting file: "
+
ex
.
Message
;
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment